Exemplo n.º 1
0
static const char* ModelicaInternal_getcwd(int dummy)
{
    const char* cwd;
    char* directory;
    
#if defined(_WIN32)
    cwd = _getcwd(buffer, sizeof(buffer));
#elif defined(_POSIX_)
    cwd = getcwd(buffer, sizeof(buffer));
#else
    ModelicaNotExistError("ModelicaInternal_getcwd");
    cwd = "";
#endif
    
    if (cwd == NULL) {
        ModelicaFormatError("Not possible to get current working directory:\n%s",
            strerror(errno));
        cwd = "";
    }
    
    directory = ModelicaAllocateString(strlen(cwd));
    strcpy(directory, cwd);
    ModelicaConvertToUnixDirectorySeparator(directory);
    return directory;
}
Exemplo n.º 2
0
static const char* ModelicaInternal_fullPathName(const char* name)
{
    /* Get full path name of file or directory */
    
    char* fullName;

#if defined(_WIN32)
    char* tempName = _fullpath(buffer, name, sizeof(buffer));
    if (tempName == NULL) {
        ModelicaFormatError("Not possible to construct full path name of \"%s\"\n%s",
            name, strerror(errno));
        return "";
    }
    fullName = ModelicaAllocateString(strlen(tempName));
    strcpy(fullName, tempName);
    ModelicaConvertToUnixDirectorySeparator(fullName);
#else
    /* No such system call in _POSIX_ available */
    char* cwd = getcwd(buffer, sizeof(buffer));
    if (cwd == NULL) {
        ModelicaFormatError("Not possible to get current working directory:\n%s",
            strerror(errno));
    }
    fullName = ModelicaAllocateString(strlen(cwd) + strlen(name) + 1);
    strcpy(fullName, cwd);
    strcat(fullName, "/");
    strcat(fullName, name);
#endif
    
    return fullName;
}
Exemplo n.º 3
0
_Ret_z_ const char* ModelicaInternal_temporaryFileName(void) {
    /* Get full path name of a temporary file name which does not exist */
    char* fullName;

    char* tempName = tmpnam(NULL);
    if (tempName == NULL) {
        ModelicaFormatError("Not possible to get temporary filename\n%s", strerror(errno));
        return "";
    }
    fullName = ModelicaAllocateString(strlen(tempName));
    strcpy(fullName, tempName);
    ModelicaConvertToUnixDirectorySeparator(fullName);

    return fullName;
}
Exemplo n.º 4
0
static const char* ModelicaInternal_getenv(const char* name, int convertToSlash, int* exist)
{
    /* Get content of environment variable */
    char* value = getenv(name);
    char* result;
    
    if (value == NULL) {
        result = ModelicaAllocateString(0);
        result[0] = '\0';
        *exist = 0;
    } else {
        result = ModelicaAllocateString(strlen(value));
        strcpy(result, value);
        if ( convertToSlash == 1 ) ModelicaConvertToUnixDirectorySeparator(result);
        *exist = 1;
    }
    return result;
}
Exemplo n.º 5
0
_Ret_z_ const char* ModelicaInternal_fullPathName(_In_z_ const char* name) {
    /* Get full path name of file or directory */

#if defined(_WIN32) || (_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || (_POSIX_VERSION >= 200112L))
    char* fullName;
    char localbuf[BUFFER_LENGTH];
#if (_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || _POSIX_VERSION >= 200112L)
    /* realpath availability: 4.4BSD, POSIX.1-2001. Using the behaviour of NULL: POSIX.1-2008 */
    char* tempName = realpath(name, localbuf);
#else
    char* tempName = _fullpath(localbuf, name, sizeof(localbuf));
#endif
    if (tempName == NULL) {
        ModelicaFormatError("Not possible to construct full path name of \"%s\"\n%s",
            name, strerror(errno));
        return "";
    }
    fullName = ModelicaAllocateString(strlen(tempName));
    strcpy(fullName, tempName);
    ModelicaConvertToUnixDirectorySeparator(fullName);
#elif defined(_POSIX_)
    char* fullName;
    char localbuf[BUFFER_LENGTH];
    /* No such system call in _POSIX_ available (except realpath above) */
    char* cwd = getcwd(localbuf, sizeof(localbuf));
    if (cwd == NULL) {
        ModelicaFormatError("Not possible to get current working directory:\n%s",
            strerror(errno));
    }
    fullName = ModelicaAllocateString(strlen(cwd) + strlen(name) + 1);
    if (name[0] != '/') {
        /* Any name beginning with "/" is regarded as already being a full path. */
        strcpy(fullName, cwd);
        strcat(fullName, "/");
    }
    strcat(fullName, name);
#else
    char* fullName = "";
    ModelicaNotExistError("ModelicaInternal_fullPathName");
#endif

    return fullName;
}