Beispiel #1
0
static int
os_createLogDir (const char *name)
{
    int result;
    os_result status;
    char dirName[OS_PATH_MAX];
    struct os_stat statBuf;
    unsigned long i;

    memset(dirName, 0, OS_PATH_MAX);
    result = 0;

    if(name)
    {
        result = 1;

        for(i=0; name[i] != '\0' && result; i++)
        {
            if((name[i] == OS_FILESEPCHAR) && (i != 0))
            {
                status = os_stat(dirName, &statBuf);

                if (status != os_resultSuccess)
                {
                    os_mkdir(dirName, S_IRWXU | S_IRWXG | S_IRWXO);
                    status = os_stat(dirName, &statBuf);
                }
                if (status != os_resultSuccess || !OS_ISDIR (statBuf.stat_mode))
                {
#ifdef WIN32
                    if((strlen(dirName) == 2) && (dirName[1] == ':'))
                    {
                        /*This is a device like for instance: 'C:'*/
                    }
                    else
                    {
                        result = 0;
                    }
#else
                    result = 0;
#endif
                }
            }
            dirName[i] = name[i];
        }
        if(result)
        {
            if(dirName[i-1] != OS_FILESEPCHAR)
            {
                status = os_stat(dirName, &statBuf);

                if (status != os_resultSuccess)
                {
                    os_mkdir(dirName, S_IRWXU | S_IRWXG | S_IRWXO);
                    status = os_stat(dirName, &statBuf);
                }

                if (status != os_resultSuccess || !OS_ISDIR (statBuf.stat_mode))
                {
#ifdef WIN32
                    if((strlen(dirName) == 2) && (dirName[1] == ':'))
                    {
                        /*This is a device like for instance: 'C:'. Check if it exists...*/
                        dirName[2] = OS_FILESEPCHAR;
                        status = os_stat(dirName, &statBuf);

                        if(status == os_resultFail)
                        {
                            result = 0;
                        }
                    }
                    else
                    {
                        result = 0;
                    }
#else
                    result = 0;
#endif
                }
            }
        }
    }
    else
    {
        result = 0;
    }

    /* os_access write access check fails for kernel mode vxworks 6.8 and 6.9
     * 	even for writeable directories.
     */
#if !( defined (VXWORKS_68) || defined (VXWORKS_69) ) || !defined (_WRS_KERNEL)
    if(result)
    {
        status = os_access(name, 2); /*Check whether dir is writable*/

        if(status != os_resultSuccess)
        {
#ifdef WIN32
            if((strlen(dirName) == 2) && (dirName[1] == ':'))
            {
                /*This is a device like for instance: 'C:'. Check if it exists...*/
                dirName[2] = OS_FILESEPCHAR;
                status = os_stat(dirName, &statBuf);

                if(status == os_resultFail)
                {
                    result = 0;
                }
            }
            else
            {
                result = 0;
            }
#else
            result = 0;
#endif
        }
    }
#endif
    return result;
}
Beispiel #2
0
os_int32
ut_dirOutNew(
    const os_char *name)
{
    os_int32 result;
    os_result status;
    char dirName[OS_PATH_MAX];
    struct os_stat statBuf;
    os_uint32 i;

    memset(dirName, 0, OS_PATH_MAX);

    if (name) {
        result = 1;

        for (i = 0; i < strlen(name) && result; i++) {
            if ((name[i] == OS_FILESEPCHAR) && (i != 0)) {
                status = os_stat(dirName, &statBuf);

                if (status != os_resultSuccess) {
                    os_mkdir(dirName, S_IRWXU | S_IRWXG | S_IRWXO);
                    status = os_stat(dirName, &statBuf);
                }
                if (!OS_ISDIR (statBuf.stat_mode)) {
#ifdef WIN32
                    if ((strlen(dirName) == 2) && (dirName[1] == ':')) {
                        /*This is a device like for instance: 'C:'*/
                    } else {
                        printf("'%s' is not a directory\n", dirName);
                        result = 0;
                        ut_outputdir = NULL;
                    }
#else
                    printf("'%s' is not a directory\n", dirName);
                    result = 0;
                    ut_outputdir = NULL;
#endif
                }
            }
            dirName[i] = name[i];
        }
        if (result) {
            if (dirName[i-1] != OS_FILESEPCHAR) {
                status = os_stat(dirName, &statBuf);

                if (status != os_resultSuccess) {
                    os_mkdir(dirName, S_IRWXU | S_IRWXG | S_IRWXO);
                    status = os_stat(dirName, &statBuf);
                }
                ut_outputdir = os_strdup(name);

                if (!OS_ISDIR(statBuf.stat_mode)) {
#ifdef WIN32
                    if ((strlen(dirName) == 2) && (dirName[1] == ':')) {
                        /*This is a device like for instance: 'C:'. Check if it exists...*/
                        dirName[2] = OS_FILESEPCHAR;
                        status = os_stat(dirName, &statBuf);

                        if (status == os_resultFail) {
                            printf("'%s' is not available", dirName);
                            result = 0;
                            ut_outputdir = NULL;
                        }
                    } else {
                        printf("'%s' is not a directory.\n", ut_outputdir);
                        result = 0;
                        ut_outputdir = NULL;
                    }
#else
                    printf("'%s' is not a directory\n", dirName);
                    result = 0;
                    ut_outputdir = NULL;
#endif
                }
            } else {
                ut_outputdir = (os_char *)os_malloc(strlen(name)+1);
                snprintf(ut_outputdir, strlen(name), "%s", name);
            }
        }
    } else {
        result = 0;
        ut_outputdir = NULL;
    }

    if (result) {
        status = os_access(ut_outputdir, 2); /* Check whether dir is writable */

        if (status != os_resultSuccess) {
#ifdef WIN32
            if ((strlen(dirName) == 2) && (dirName[1] == ':')) {
                /*This is a device like for instance: 'C:'. Check if it exists...*/
                dirName[2] = OS_FILESEPCHAR;
                status = os_stat(dirName, &statBuf);

                if (status == os_resultFail) {
                    printf("'%s' cannot be found", dirName);
                    result = 0;
                    ut_outputdir = NULL;
                }
            } else {
                printf("Specified output directory '%s' is not writable.\n", ut_outputdir);
                result = 0;
                ut_outputdir = NULL;
            }
#else
            printf("Specified output directory '%s' is not writable.\n", ut_outputdir);
            result = 0;
            ut_outputdir = NULL;
#endif
        }
    }

    return result;
}
Beispiel #3
0
static int
idl_createDir (
    os_char* fname)
{
    char *pathName;
    os_result statRes;
    struct os_stat statbuf;
    char* outdir;
    os_char* stackScope;
    os_char* token;
    const os_char* osSep;

    /* to allow nested modules which may potentially lead to very long paths,
     * pathName is not allocated fixed-size on stack
     * but dynamically on heap
     */
    pathName = os_malloc(1);
    pathName[0] = '\0';
    outdir = idl_dirOutCur();
    if(outdir){
        pathName = os_realloc(pathName, strlen(outdir) + strlen(os_fileSep()) + 1);
        if (pathName == NULL) {
            printf("Memory allocation failure when creating idl directory\n");
            return 0;
        }
        os_sprintf(pathName, "%s%s", outdir, os_fileSep());
    }
    /* make sure that we replace the os file seperator with a simple character
     * like '/', this will allow us to parse easier later.
     */
    osSep = os_fileSep();
    stackScope = idl_genJavaHelperSubstitute(fname, osSep, "/", NULL);

    if(stackScope[0] != '\0'){ /* strlen(stackScope) > 0 */
        do
        {
            token = strchr(stackScope, '/');
            /* make sure this is not the last part of the file name, for example
             * for the file name org/opensplice/foo.java we only want to create
             * directories for org and opensplice, the foo.java part is not a
             * directory. So we can simply state if no '/' char can be
             * found then we must be at the end part of the file name!
             */
            if(token)
            {
                *token = '\0';
                token++;
                /* reallocate pathName to include stackScope */
                pathName = os_realloc(pathName, strlen(pathName) + strlen(stackScope) + 1);
                if (pathName == NULL) {
                    printf("Memory allocation failure when trying to create idl directory %s, \
                            probably the path has grown too long\n", stackScope);
                    return 0;
                }
                os_strcat (pathName, stackScope);
                stackScope = token;
                statRes = os_stat (pathName, &statbuf);
                if (statRes == os_resultFail) {
                    /* @todo                                                      */
                    /* Assume the file does not exist. On some platforms          */
                    /* a check to see if errno == ENOENT would be more conclusive */
                    /* That fails on WIN32 however because stat is not fully      */
                    /* compatible. Only an os_stat implementation can solve that. */

                    os_mkdir(pathName, 0777);
                    statRes = os_stat(pathName, &statbuf);
                } else {
                    if (!OS_ISDIR(statbuf.stat_mode)) {
                        printf ("File %s already exists, but is not a directory\n", pathName);
                        os_free(pathName);
                        return 0;
                    }
                }
                if (statRes == os_resultFail) {
                    printf ("Error when creating directory %s\n", pathName);
                    os_free(pathName);
                    return 0;
                }
                /* reallocate pathName to include os_fileSep() */
                pathName = os_realloc(pathName, strlen(pathName) + strlen(stackScope) + strlen(os_fileSep()) + 1);
                if (pathName == NULL) {
                    printf("Memory allocation failure when trying to add the \
                            file separator to idl directory %s", stackScope);
                    return 0;
                }
                os_strcat (pathName, os_fileSep());
            }
        } while(token);