55 #include <sys/types.h>
72 # define lstat64 lstat
93 nameLength = strlen(name);
104 if (strstr(name,
"/") != NULL || name[0] ==
'~' || name[0] ==
'.')
107 if (done ==
false ||
fileExists(tempPath) ==
false)
112 strcpy(fullName, tempPath);
121 strcat(tempPath,
"/");
122 strcat(tempPath, name);
125 strcpy(fullName, name);
130 currentpath = getenv(
"PATH");
131 if (currentpath == NULL)
136 sep = strchr(currentpath,
':');
140 int i = sep - currentpath;
141 strncpy(tempPath, currentpath, i);
143 strcat(tempPath,
"/");
144 strcat(tempPath, name);
147 strcpy(fullName, tempPath);
150 currentpath = sep + 1;
151 sep = strchr(currentpath,
':');
154 if (*currentpath !=
'\0')
156 strcpy(tempPath, currentpath);
157 strcat(tempPath,
"/");
158 strcat(tempPath, name);
161 strcpy(fullName, tempPath);
195 if (*fullName !=
'\0')
201 size_t len = strlen(name);
208 strcpy(tempPath, name);
212 strcpy(fullName, tempPath);
230 struct stat64 filestat;
233 rc = stat64(fname, &filestat);
236 if (S_ISREG(filestat.st_mode))
257 const char *endPtr = pathName + file->
getLength() - 1;
261 while (pathName < endPtr)
289 const char *endPtr = pathName + file->
getLength() - 1;
293 while (pathName < endPtr)
301 else if (*endPtr ==
'.')
325 const char *endPtr = pathName + file->
getLength() - 1;
329 while (pathName < endPtr)
354 const char *endPtr = name + strlen(name) - 1;
358 while (name < endPtr)
366 else if (*endPtr ==
'.')
390 return name[0] ==
'~' || name[0] ==
'/' || name[0] ==
'.';
428 char tempName[PATH_MAX + 3];
431 strncpy(tempName, name,
sizeof(tempName));
432 if (extension != NULL)
434 strncat(tempName, extension,
sizeof(tempName) - strlen(tempName) - 1);
441 for (
int i = 0; i < 2; i++)
456 for (
int i = 0; i < 2; i++)
483 size_t nameLength = strlen(name);
485 if (nameLength < 1 || nameLength > PATH_MAX + 1)
491 strcpy(resolvedName, name);
502 if (stat64(resolvedName, &dummy) == 0)
505 if (S_ISREG(dummy.st_mode))
530 const char *pathEnd = path + strlen(path);
532 const char *p = path;
533 const char *q = strchr(p,
':');
535 for (; p < pathEnd; p = q + 1, q = strchr(p,
':'))
543 size_t sublength = q - p;
545 memcpy(resolvedName, p, sublength);
546 resolvedName[sublength] =
'/';
547 resolvedName[sublength + 1] =
'\0';
548 strncat(resolvedName, name, PATH_MAX - strlen(resolvedName));
555 if (stat64(resolvedName, &dummy) == 0)
558 if (S_ISREG(dummy.st_mode))
586 if (name[1] ==
'\0' || name[1] ==
'/')
589 char tempName[PATH_MAX + 3];
591 strncpy(tempName, name, PATH_MAX + 1);
592 strcpy(name, getenv(
"HOME"));
594 strncat(name, tempName + 1, PATH_MAX - strlen(name));
600 char tempName[PATH_MAX + 3];
601 char userName[PATH_MAX + 3];
604 strncpy(tempName, name, PATH_MAX - strlen(tempName));
606 char *slash = strchr(tempName,
'/');
611 size_t nameLength = slash - tempName - 1;
612 memcpy(userName, tempName + 1, nameLength);
613 userName[nameLength] =
'\0';
618 strcpy(userName, tempName + 1);
622 struct passwd *ppwd = getpwnam(userName);
630 strncpy(name, ppwd->pw_dir, PATH_MAX - strlen(name));
634 strncat(name, slash, PATH_MAX - strlen(name));
643 else if (name[0] !=
'/')
645 char tempName[PATH_MAX + 2];
647 strncpy(tempName, name, PATH_MAX + 1);
648 if (getcwd(name, PATH_MAX + 1) == NULL)
652 strncat(name,
"/", PATH_MAX - strlen(name));
653 strncat(name, tempName, PATH_MAX - strlen(name));
661 char tempName[PATH_MAX + 2];
664 strcpy(name, tempName);
691 char *dest = resolved;
696 for (
const char *p = name; *p; p++ )
701 if ( *(p + 1) !=
'.' )
712 else if ( *p ==
'.' )
716 char next = *(p + 1);
717 if ( next ==
'\0' || next ==
'/' )
724 else if ( next ==
'.' )
730 if ( next ==
'\0' || next ==
'/' )
737 while ( prevSl > resolved )
739 if ( *--prevSl ==
'/' )
761 (*dest ==
'/' && dest != resolved) ? *dest =
'\0' : *++dest =
'\0';
776 return unlink(name) == 0;
788 return remove(name) == 0;
804 int rc = stat64(name, &finfo);
805 return rc == 0 && S_ISDIR(finfo.st_mode);
818 return access(name, W_OK) != 0;
832 return access(name, R_OK) != 0;
849 int rc = stat64(name, &finfo);
850 return rc == 0 && (S_ISREG(finfo.st_mode) || S_ISBLK(finfo.st_mode));
865 int rc = stat64(name, &finfo);
883 if (stat64(name, &st))
901 if (stat64(name, &st) != 0)
918 return mkdir(name, S_IRWXU | S_IRWXG | S_IRWXO) != -1;
932 return rename(oldName, newName) == 0;
951 size_t length = strlen(name);
952 for (
size_t index = length - 1; index > 0; index--)
954 if (name[index] ==
'.' && (index > 0 && name[index - 1] ==
'/'))
974 struct stat64 statbuf;
975 struct utimbuf timebuf;
976 if (stat64(name, &statbuf) != 0)
981 timebuf.actime = statbuf.st_atime;
982 timebuf.modtime = (time_t)time;
983 return utime(name, &timebuf) == 0;
997 struct stat64 buffer;
998 if (stat64(name, &buffer) != 0)
1002 mode_t mode = buffer.st_mode;
1004 mode = mode & 07555;
1005 return chmod(name, mode) == 0;
1131 strcpy(buffer,
entry->d_name);
RexxString * new_string(const char *s, stringsize_t l)
const char * getStringData()
SysFileIterator(const char *pattern)
static bool fileExists(const char *name)
static bool checkCurrentFile(const char *name, char *resolvedName)
static bool moveFile(const char *oldName, const char *newName)
static bool setLastModifiedDate(const char *name, int64_t time)
static bool canonicalizeName(char *name)
static const char * getSeparator()
static bool deleteFile(const char *name)
static bool normalizePathName(const char *name, char *resolved)
static bool deleteDirectory(const char *name)
static RexxString * extractFile(RexxString *file)
static bool setFileReadOnly(const char *name)
static const char * EOL_Marker
static bool hasDirectory(const char *name)
static const char * getTempFileName()
static int64_t getLastModifiedDate(const char *name)
static const char * getPathSeparator()
static int getRoots(char *roots)
static bool primitiveSearchName(const char *name, const char *path, const char *extension, char *resolvedName)
static bool searchName(const char *name, const char *path, const char *extension, char *resolvedName)
static bool makeDirectory(const char *name)
static RexxString * extractDirectory(RexxString *file)
static RexxString * extractExtension(RexxString *file)
static const char PathDelimiter
static bool isDirectory(const char *name)
static bool searchPath(const char *name, const char *path, char *resolvedName)
static bool isCaseSensitive()
static uint64_t getFileLength(const char *name)
static bool isWriteOnly(const char *name)
static void qualifyStreamName(const char *unqualifiedName, char *qualifiedName, size_t bufferSize)
static bool hasExtension(const char *name)
static const char EOF_Marker
static bool searchFileName(const char *name, char *fullName)
static bool isHidden(const char *name)
static bool isReadOnly(const char *name)
static bool exists(const char *name)
static bool isFile(const char *name)
static void strlower(char *str)
unsigned __int64 uint64_t