static void set_game_filename(const char *name) { n_free(game_filename); game_filename = 0; #if defined(_GNU_SOURCE) game_filename = canonicalize_file_name(name); #else #if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) game_filename = (char *) n_malloc(PATH_MAX); if(!realpath(name, game_filename)) { n_free(game_filename); game_filename = 0; } #else #ifdef __DJGPP__ game_filename = (char *) n_malloc(FILENAME_MAX); _fixpath(name, game_filename); #endif #endif #endif if(!game_filename) game_filename = n_strdup(name); }
int os_get_abs_filename(char *buf, size_t buflen, const char *filename) { char tmp[FILENAME_MAX]; char *p; /* if the filename is empty, use "." */ if (filename[0] == '\0') filename = "."; /* "fix" the path - this expands the filename to an absolute path */ _fixpath(filename, tmp); /* ...it also changes \ to /, so undo that to keep things in DOS format */ for (p = tmp ; *p != '\0' ; ++p) { if (*p == '/') *p = '\\'; } /* if the result fits the buffer, send it back, otherwise fail */ if (strlen(tmp) < buflen) { strcpy(buf, tmp); return TRUE; } else return FALSE; }
char* expand_path( const char *src, char *dest ) { #ifdef _TARGET_UNIX_ realpath( src, dest); #endif #ifdef _TARGET_GO32_ _fixpath( src, dest ); #endif return dest; }
/** * realpath: get the complete path */ char * realpath(const char *in_path, char *out_path) { #ifdef __DJGPP__ /* * I don't use _fixpath or _truename in LFN because neither guarantee * a complete long name. This is mainly DOS's fault, since the cwd can * be a mixture of long and short components. */ if (_USE_LFN) { strlimcpy(out_path, in_path, MAXPATHLEN); canonpath(out_path); } else _fixpath(in_path, out_path); #else _fullpath(out_path, in_path, MAXPATHLEN); canonpath(out_path); #endif return out_path; }
int stat(const char *path, struct stat *buf) { static int stat_called_before = 0; char p[1090]; /* Should be p[PATH_MAX+1] */ int status; /* Normalize the path */ _fixpath(path, p); /* Work around strange bug with stat and time */ if (!stat_called_before) { stat_called_before = 1; (void) time((time_t *) 0); } /* Check for root path */ if (strcmp(p, "/") == 0 || strcmp(p + 1, ":/") == 0) { /* Handle root path as special case, stat_assist doesn't like the root directory. */ if (p[1] == ':') { if (p[0] >= 'a' && p[0] <= 'z') buf->st_dev = p[0] - 'a'; else buf->st_dev = p[0] - 'A'; } else buf->st_dev = -1; /* No device? */ buf->st_ino = 2; /* Root path always inode 2 */ buf->st_mode = S_IFDIR | S_IREAD | S_IWRITE | S_IEXEC; buf->st_nlink = 1; buf->st_uid = getuid(); buf->st_gid = getgid(); buf->st_rdev = buf->st_dev; buf->st_size = 0; buf->st_atime = 0; buf->st_mtime = 0; buf->st_ctime = 0; buf->st_blksize = 512; /* Not always correct? */ status = 0; } else { status = _stat_assist(p, buf); /* Make inode numbers unique */ if (status == 0) status = fixinode(p, buf); /* The stat_assist does something weird with st_dev, but sets st_rdev to the drive number. Fix st_dev. */ buf->st_dev = buf->st_rdev; /* Make all files owned by ourself. */ buf->st_uid = getuid(); buf->st_gid = getgid(); /* Make all directories writable. They always are in DOS, but stat_assist doesn't think so. */ if (S_ISDIR(buf->st_mode)) buf->st_mode |= S_IWRITE; } return status; }