dirOK-linux.c 998 Bytes
Newer Older
ofgeorg's avatar
ofgeorg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "benchmarkshelper.h"

/* Checks if sDir exists, 
   creates it if not
   checks if is writable thereafter
   Fatal ERROR if anything fails
*/
void dirOK(char *sDir)
{
    char sLoc[256], fileNameLoc[1024];
    if (strlen(sDir) > 1024)
        ERROR("pathName too long %s\n",sDir); 
    sprintf(sLoc, "test -d %s", sDir); 
    if ( system(sLoc) )  /* does  NOT exist */
    {
        sprintf(sLoc, "mkdir %s", sDir);
        system(sLoc);
    }
    /* could we make the dir ? */
    sprintf(sLoc, "test -d %s", sDir);
    if ( system(sLoc) )  /* does  NOT exist */
        ERROR("Failed to create dir %s", sDir);
    /* is dir writable */
    createFullFileName(fileNameLoc, sDir, "toto");
    sprintf(sLoc, "touch %s", fileNameLoc);
    if ( system(sLoc) )  /* failed */
        ERROR("Problem writing in dir %s", sDir);
    else
        unlink(fileNameLoc);
    return;
}