152 #if defined( HAVE_LOCALE_H )
157 #include "PlatformDefinitions.h"
159 #if defined( HAVE_SYS_WAIT_H )
160 # include <sys/wait.h>
166 #if defined( HAVE_MALLOC_H )
179 #include <sys/stat.h>
182 #include <sys/types.h>
184 #include <sys/syscall.h>
186 #include <sys/utsname.h>
189 #include <semaphore.h>
195 #if defined( HAVE_SYS_SEM_H )
196 # include <sys/sem.h>
200 #include <sys/time.h>
204 #if defined( HAVE_SYS_SELECT_H )
205 # include <sys/select.h>
208 #if defined( HAVE_SYS_LDR_H )
209 # include <sys/ldr.h>
212 #if defined( HAVE_STRINGS_H )
213 # include <strings.h>
218 #if defined( HAVE_SYS_UTSNAME_H )
219 # include <sys/utsname.h>
224 #if defined( HAVE_SYS_RESOURCE_H )
225 # include <sys/resource.h>
228 #if defined( HAVE_FEATURES_H )
229 # include <features.h>
232 #if defined( HAVE_NL_TYPES_H )
233 # include <nl_types.h>
240 #if !defined( HAVE_UNION_SEMUN )
248 #if defined __APPLE__
252 # define lstat64 lstat
258 #define INVALID_ROUTINE 40
260 #define NO_UTIL_ERROR "0"
261 #define VALID_ROUTINE 0
263 #define MAX_LINE_LEN 4096
264 #define MAX_READ 0x10000
269 #define IBUF_LEN 4096
270 #define CURRENT_DIR_FIRST 0
271 #define ENVIRONMENT_ONLY 1
274 #define MAXUSECOUNT 65535
275 #define REXXMESSAGEFILE "rexx.cat"
278 #define FNAMESPEC_BUF_LEN IBUF_LEN
279 #define FOUNDFILE_BUF_LEN IBUF_LEN
280 #define FILETIME_BUF_LEN 64
281 #define FILEATTR_BUF_LEN 16
282 #define FOUNDFILELINE_BUF_LEN FOUNDFILE_BUF_LEN + FILETIME_BUF_LEN + FILEATTR_BUF_LEN
298 #define pi 3.14159265358979323846l
304 #define DEFAULT_PRECISION 9
305 #define MAX_PRECISION 16
313 #define NO_UTIL_ERROR "0"
314 #define ERROR_NOMEM "2"
315 #define ERROR_FILEOPEN "3"
321 #define ERROR_RETSTR "ERROR:"
327 #define INVALID_ROUTINE 40
328 #define VALID_ROUTINE 0
333 #define SORT_CASESENSITIVE 0
334 #define SORT_CASEIGNORE 1
337 #define SORT_ASCENDING 0
338 #define SORT_DECENDING 1
340 #define SORT_NUMERIC 3
342 #define SORT_DEF_AVG_SIZE 20
348 #define BUILDRXSTRING(t, s) { \
349 strcpy((t)->strptr,(s));\
350 (t)->strlength = strlen((s)); \
356 #define RETVAL(retc) { \
357 snprintf(retstr->strptr, DEFRXSTRING, "%d", retc); \
358 retstr->strlength = strlen(retstr->strptr); \
359 return VALID_ROUTINE; \
366 #define RECURSE 0x0002
367 #define DO_DIRS 0x0004
368 #define DO_FILES 0x0008
369 #define NAME_ONLY 0x0010
370 #define EDITABLE_TIME 0x0020
371 #define LONG_TIME 0x0040
372 #define CASELESS 0x0080
380 #define stty(a,b) (void)tcsetattr(a,TCSANOW,b)
381 #define gtty(a,b) (void)tcgetattr(a,b)
382 #define discard_input(a) tcflush(a,TCIFLUSH)
383 #define restore_tty(a) stty(ttyfd,a)
492 length = strlen(
string);
503 if (!isdigit(*
string))
508 accumulator = accumulator * 10 + (*
string -
'0');
512 *number = accumulator;
544 if (filedata->
data != size)
553 filedata->
data = (size_t)(endptr - filedata->
buffer);
566 for(;*
string !=
'\0';
string++){
567 *
string = toupper(*
string);
585 char * endptr = NULL;
588 if((filedata->
handle = fopen(file,
"r")) == NULL)
591 if((stat64(file,&finfo) == -1)||(!finfo.st_size)){
597 if((filedata->
buffer = (
char *)malloc(finfo.st_size)) == NULL ){
601 filedata->
size = finfo.st_size;
605 finfo.st_size, filedata->
handle);
606 if(filedata->
data != (
size_t)finfo.st_size){
614 filedata->
data = (size_t)(endptr - filedata->
buffer);
623 filedata->
size = finfo.st_size;
668 if (!(filedata->
data)) {
678 scan = (
const char *)memchr(filedata->
scan,
CH_NL, filedata->
data);
681 length = scan - filedata->
scan;
683 if (copylength > size)
688 memcpy(
line, filedata->
scan, copylength);
689 line[copylength] =
'\0';
693 line[copylength - 1] =
'\0';
696 filedata->
data -= length + 1;
697 filedata->
scan = scan + 1;
699 if (!filedata->
data) {
724 if (size > filedata->
data)
726 copylength = filedata->
data;
728 memcpy(
line, filedata->
scan, copylength);
729 line[copylength] =
'\0';
732 filedata->
data -= copylength;
734 filedata->
scan += copylength;
740 return GetLine(
line + copylength, size - copylength, filedata);
744 copylength = filedata->
data;
745 if (size < copylength)
750 memcpy(
line, filedata->
scan, copylength);
751 line[copylength] =
'\0';
786 const char *haystack,
799 for (p = 0; p < hlen; p++) {
801 if (haystack[p] ==
'\0')
804 line[p] = haystack[p];
805 else line[p] = toupper(haystack[p]);
810 for (p = 0; p < nlen; p++) {
812 if (needle[p] ==
'\0')
815 target[p] = needle[p];
816 else target[p] = toupper(needle[p]);
819 const char *hit = strstr(
line, target);
825 return haystack + (hit -
line);
851 for(i=0;(**ppenv !=
':')&&(**ppenv !=
'\0');(*ppenv)++){
854 path_buf[i++] = **ppenv;
872 const char * filename,
887 while((ep = readdir(dp))){
889 if(!strcmp(ep->d_name,filename)){
890 if(!getcwd(buf,buf_size))
892 length = strlen(buf);
893 if((length+2+strlen(filename))>buf_size)
896 buf[length+1] =
'\0';
897 strcat(buf,filename);
914 dp = opendir(path_buf);
916 while((ep = readdir(dp))){
918 if(!strcmp(ep->d_name,filename)){
919 if(strlen(path_buf)>buf_size)
921 strcpy(buf,path_buf);
922 length = strlen(buf);
923 if((length+2+strlen(filename))>buf_size)
926 buf[length+1] =
'\0';
927 strcat(buf,filename);
960 if (*
string ==
'-') {
965 length = strlen(
string);
973 if (!isdigit(*
string))
976 accumulator = accumulator * 10 + (*
string -
'0');
980 *number = accumulator * sign;
1001 int ttyfd = STDIN_FILENO;
1003 struct sigaction new_action;
1008 sigfillset(&new_action.sa_mask);
1009 new_action.sa_flags = SA_RESTART;
1012 sigaction(SIGINT, &new_action, NULL);
1013 sigaction(SIGTERM, &new_action, NULL);
1014 sigaction(SIGQUIT, &new_action, NULL);
1015 sigaction(SIGHUP, &new_action, NULL);
1016 sigaction(SIGTSTP, &new_action, NULL);
1017 sigaction(SIGTTIN, &new_action, NULL);
1018 sigaction(SIGTTOU, &new_action, NULL);
1020 sigaction(SIGSEGV, &new_action, NULL);
1021 sigaction(SIGFPE, &new_action, NULL);
1022 sigaction(SIGILL, &new_action, NULL);
1023 sigaction(SIGBUS, &new_action, NULL);
1024 sigaction(SIGPIPE, &new_action, NULL);
1027 if( !isatty(ttyfd) ){
1031 ttyfd = STDIN_FILENO;
1034 ttyfd = open(
"/dev/tty", O_RDONLY);
1036 struct termios in_raw;
1043 gtty(ttyfd, &in_raw);
1045 in_raw.c_lflag &= ~ICANON;
1047 in_raw.c_lflag &= ~ECHO;
1048 in_raw.c_cc[VMIN] = 1;
1049 in_raw.c_cc[VTIME] = 0;
1050 stty(ttyfd, &in_raw);
1076 if (context->ObjectToDouble(delay, &seconds) == 0 ||
1077 isnan(seconds) || seconds == HUGE_VAL || seconds == -HUGE_VAL)
1085 if (seconds < 0.0 || seconds > 999999999)
1089 context->ArrayOfFive(context->String(
"positional"), context->String(
"delay"),
1090 context->String(
"0"), context->String(
"999999999"), delay));
1095 long secs = (long) seconds;
1096 long nanoseconds = (long) ((seconds - secs) * 1000000000);
1098 #if defined( HAVE_NANOSLEEP )
1099 struct timespec Rqtp, Rmtp;
1101 Rqtp.tv_nsec = nanoseconds;
1102 nanosleep(&Rqtp, &Rmtp);
1103 #elif defined( HAVE_NSLEEP )
1104 struct timestruc_t Rqtp, Rmtp;
1106 Rqtp.tv_nsec = nanoseconds;
1107 nsleep(&Rqtp, &Rmtp);
1160 int ignore = system(
"clear");
1198 context->InvalidRoutine();
1234 context->InvalidRoutine();
1267 unsigned short position;
1345 char * dir_buf = NULL;
1348 if (numargs < 1 || numargs > 2)
1362 if (numargs < 2 || !
string2int(args[1].strptr, &mode))
1364 mode = S_IRWXU | S_IRWXG | S_IRWXO;
1366 rc = mkdir(path, mode);
1427 char * dir_buf = NULL;
1454 #if defined( ENOTEMPTY ) && defined( EEXIST )
1460 #elif defined( ENOTEMPTY )
1466 #elif defined( EEXIST )
1513 char * dir_buf = NULL;
1592 bool linenums =
false;
1594 bool sensitive =
false;
1598 char * dir_buf = NULL;
1603 if (numargs < 3 || numargs > 4 ||
1618 if (strstr(opts,
"N") || strstr(opts,
"n"))
1621 if (strstr(opts,
"C") || strstr(opts,
"c"))
1638 line = (
char *) malloc(4096 *
sizeof(
char));
1645 ptr =
mystrstr(
line, target, len, args[0].strlength, sensitive);
1648 snprintf(ldp.
ibuf,
sizeof ldp.
ibuf,
"%d ", (
int)num);
1649 len2 = strlen(ldp.
ibuf);
1731 if (numargs < 2 || numargs > 3 ||
1739 if ((*opts ==
'N') || (*opts ==
'n'))
1743 else if ((*opts ==
'C') || (*opts ==
'c'))
1750 ulRc =
SearchPath(SearchFlag, args[0].strptr, args[1].strptr,
1751 (
char *)buf,
sizeof(buf));
1757 char *temp = strdup(args[0].strptr);
1759 ulRc =
SearchPath(SearchFlag, temp, args[1].strptr,
1760 (
char *)buf,
sizeof(buf));
1779 struct utsname info;
1784 if(uname(&info) < 0)
1804 struct utsname info;
1809 if(uname(&info) < 0)
1812 snprintf(retstr->
strptr,
DEFRXSTRING,
"%s %s.%s",info.sysname, info.version, info.release);
1849 if (semdata == NULL) {
1850 return context->String(
"");
1854 semdata->
handle = (sem_t *)malloc(
sizeof(sem_t));
1855 rc = sem_init(semdata->
handle, 0, 0);
1858 return context->String(
"");
1860 semdata->
named =
false;
1864 semdata->
handle = sem_open(name, (O_CREAT | O_EXCL), (S_IRWXU | S_IRWXG), 0);
1865 if (semdata->
handle == SEM_FAILED ) {
1867 return context->String(
"");
1869 semdata->
named =
true;
1871 return context->Uintptr((
uintptr_t)semdata);
1890 if (semdata == NULL) {
1893 semdata->
handle = sem_open(name, 0);
1894 if (semdata->
handle == SEM_FAILED ) {
1897 semdata->
named =
true;
1916 sem_init(semdata->
handle, 1, 0);
1936 rc = sem_post(semdata->
handle);
1958 if (semdata->
named ==
false) {
1960 if (sem_destroy(semdata->
handle)) {
1961 if (errno == EINVAL) {
1971 if (sem_close(semdata->
handle)) {
1972 if (errno == EINVAL) {
1985 #define SEM_WAIT_PERIOD 100
2007 while (timeout > 0) {
2008 rc = sem_trywait(semdata->
handle);
2018 rc = sem_wait(semdata->
handle);
2021 if (errno == EAGAIN) {
2024 else if (errno == EINVAL) {
2051 if (semdata == NULL) {
2052 return context->String(
"");
2054 if (strlen(name) == 0) {
2056 semdata->
handle = (sem_t *)malloc(
sizeof(sem_t));
2057 rc = sem_init(semdata->
handle, 0, 0);
2060 return context->String(
"");
2062 semdata->
named =
false;
2066 semdata->
handle = sem_open(name, (O_CREAT | O_EXCL), (S_IRWXU | S_IRWXG), 0);
2067 if (semdata->
handle == SEM_FAILED ) {
2069 return context->String(
"");
2071 semdata->
named =
true;
2073 rc = sem_post(semdata->
handle);
2074 return context->Uintptr((
uintptr_t)semdata);
2093 if (semdata == NULL) {
2096 semdata->
handle = sem_open(name, 0);
2097 if (semdata->
handle == SEM_FAILED ) {
2100 semdata->
named =
true;
2124 while (timeout > 0) {
2125 rc = sem_trywait(semdata->
handle);
2135 rc = sem_wait(semdata->
handle);
2138 if (errno == EAGAIN) {
2141 else if (errno == EINVAL) {
2165 rc = sem_getvalue(semdata->
handle, &val);
2167 if (errno == EINVAL) {
2175 rc = sem_post(semdata->
handle);
2199 if (semdata->
named ==
false) {
2201 if (sem_destroy(semdata->
handle)) {
2202 if (errno == EINVAL) {
2212 if (sem_close(semdata->
handle)) {
2213 if (errno == EINVAL) {
2246 while ( have < need )
2289 snprintf(buf,
sizeof(buf),
"%s() argument %lu must be less than %lu characters in length; length is %lu",
2290 funcName, pos, len, realLen);
2304 char buf[256] = {0};
2305 snprintf(buf,
sizeof(buf),
2306 "SysFileTree argument %lu must be a combination of F, D, B, S, T, L, I, or O; found \"%s\"",
2400 if ( *nPath != nStaticBuffer )
2406 *dPath = (
char *)malloc(*nPath *
sizeof(
char));
2408 if ( *dPath == NULL )
2428 return (S_ISREG(m) ||
2442 else if ( S_ISBLK(m) )
2446 else if ( S_ISCHR(m) )
2450 else if ( S_ISDIR(m) )
2454 else if ( S_ISFIFO(m) )
2458 else if ( S_ISSOCK(m) )
2487 struct stat *finfo,
char **d_name,
bool caseless)
2491 char *dFullPath = fullPath;
2494 struct dirent *dir_entry = readdir(dir_handle);
2495 if( dir_entry == NULL )
2502 len = snprintf(dFullPath, nFullPath,
"%s%s", path, dir_entry->d_name);
2503 if ( len >= (
int)nFullPath )
2516 lstat(dFullPath, finfo);
2526 char *pDest = dup_d_name;
2527 char *pSrc = dir_entry->d_name;
2529 for ( ; *pSrc; pDest++, pSrc++ )
2531 *pDest = toupper(*pSrc);
2535 if ( fnmatch(fileSpec, dup_d_name, FNM_NOESCAPE | FNM_PATHNAME | FNM_PERIOD ) == 0 )
2537 *d_name = dir_entry->d_name;
2548 if ( fnmatch(fileSpec, dir_entry->d_name, FNM_NOESCAPE | FNM_PATHNAME | FNM_PERIOD) == 0 )
2550 *d_name = dir_entry->d_name;
2560 dir_entry = readdir(dir_handle);
2562 while( dir_entry != NULL );
2591 struct stat *finfo,
char **d_name,
bool caseless)
2594 char *dFullPath = fullPath;
2597 struct dirent *dir_entry = readdir(dir_handle);
2598 if( dir_entry == NULL )
2605 int len = snprintf(dFullPath, nFullPath,
"%s%s", path, dir_entry->d_name);
2606 if ( len >= (
int)nFullPath )
2614 dFullPath = (
char *)malloc(nFullPath *
sizeof(
char));
2615 if ( dFullPath == NULL )
2621 snprintf(dFullPath,
sizeof fullPath,
"%s%s", path, dir_entry->d_name);
2624 lstat(fullPath, finfo);
2626 if ( S_ISDIR(finfo->st_mode) )
2634 char *pDest = dup_d_name;
2635 char *pSrc = dir_entry->d_name;
2637 for ( ; *pSrc; pDest++, pSrc++ )
2639 *pDest = toupper(*pSrc);
2643 if ( fnmatch(fileSpec, dup_d_name, FNM_NOESCAPE | FNM_PATHNAME | FNM_PERIOD ) == 0 )
2645 *d_name = dir_entry->d_name;
2651 if ( fnmatch(fileSpec, dir_entry->d_name, FNM_NOESCAPE | FNM_PATHNAME | FNM_PERIOD) == 0 )
2653 *d_name = dir_entry->d_name;
2658 dir_entry = readdir(dir_handle);
2660 while( dir_entry != NULL );
2683 switch( toupper(*opts) )
2750 if ( strlen(opts) == 0 )
2756 if ( !
goodOpts(context, opts, options) )
2797 size_t len = strlen(fSpec);
2803 if ( len >= bufLen - 1)
2808 strcpy(fileSpec, fSpec);
2811 if ( len == 1 && fileSpec[0] ==
'*' )
2813 strcpy(fileSpec,
"./*");
2817 if ( fileSpec[len - 1] ==
'/' )
2819 strcat(fileSpec,
"*");
2823 if ( fileSpec[0] ==
'~' )
2832 if ( strlen(temp) >= bufLen )
2839 strcpy(fileSpec, temp);
2861 int len = strlen(fileSpec);
2870 while( fileSpec[slashPos] !=
'/' && slashPos >= 0 );
2872 if ( fileSpec[slashPos] ==
'/' )
2876 if ( fileSpec[slashPos + 1] !=
'\0' )
2878 l = strlen(&fileSpec[slashPos + 1]) + 1;
2886 strcpy(treeData->
dFNameSpec, &fileSpec[slashPos + 1]);
2897 l = strlen(&fileSpec[slashPos + 1]) + 1;
2905 strcpy(treeData->
dFNameSpec, &fileSpec[slashPos + 1]);
2908 *lastSlashPos = slashPos;
2926 char *dPath = *path;
2927 size_t nPath = *pathLen;
2929 if ( fileSpec[lastSlashPos] !=
'/' )
2933 while ( getcwd(dPath, nPath) == NULL )
2942 if ( strlen(dPath) + 1 > nPath )
2958 size_t l = lastSlashPos + 1 + 1;
2962 dPath = (
char *)malloc(nPath *
sizeof(
char));
2964 if ( dPath == NULL )
2970 strncpy(dPath, fileSpec, lastSlashPos + 1);
2972 *(dPath + lastSlashPos + 1) =
'\0';
2981 if ( chdir(dPath) == 0 )
2983 while ( getcwd(dPath, nPath) == NULL )
2989 int ignore = chdir(savedPath);
2994 if ( strlen(dPath) + 1 > nPath )
3004 if ( lastSlashPos > 0 )
3010 int ignore = chdir(savedPath);
3015 if ( nPath != *pathLen )
3063 if ( strcmp(fileSpec,
".") == 0 )
3065 strcpy(fileSpec,
"./*");
3067 else if ( strcmp(fileSpec,
"..") == 0 )
3069 strcpy(fileSpec,
"../*");
3079 if ( !
getPathSegment(c, fileSpec, path, pathLen, lastSlashPos) )
3130 struct tm *timestamp;
3147 struct tm stTimestamp;
3148 timestamp = localtime_r(&(finfo->st_mtime), &stTimestamp);
3150 timestamp = localtime(&(finfo->st_mtime));
3155 snprintf(treeData->
fileTime,
sizeof treeData->
fileTime,
"%4d-%02d-%02d %02d:%02d:%02d %10lu ",
3156 timestamp->tm_year + 1900,
3157 timestamp->tm_mon + 1,
3162 (
unsigned long)finfo->st_size);
3168 snprintf(treeData->
fileTime,
sizeof treeData->
fileTime,
"%02d/%02d/%02d/%02d/%02d %10lu ",
3169 (timestamp->tm_year) % 100,
3170 timestamp->tm_mon + 1,
3174 (
unsigned long)finfo->st_size);
3178 snprintf(treeData->
fileTime,
sizeof treeData->
fileTime,
"%2d/%02d/%02d %2d:%02d%c %10lu ",
3179 timestamp->tm_mon+1,
3181 timestamp->tm_year % 100,
3182 timestamp->tm_hour < 13 ? timestamp->tm_hour : timestamp->tm_hour - 12,
3184 (timestamp->tm_hour < 12 || timestamp->tm_hour == 24) ?
'a' :
'p',
3185 (
unsigned long)finfo->st_size);
3190 snprintf(treeData->
fileAttr,
sizeof treeData->
fileAttr,
"%c%c%c%c%c%c%c%c%c%c ",
3192 (finfo->st_mode & S_IREAD) ?
'r' :
'-',
3193 (finfo->st_mode & S_IWRITE) ?
'w' :
'-',
3194 (finfo->st_mode & S_IEXEC) ?
'x' :
'-',
3195 (finfo->st_mode & S_IRGRP) ?
'r' :
'-',
3196 (finfo->st_mode & S_IWGRP) ?
'w' :
'-',
3197 (finfo->st_mode & S_IXGRP) ?
'x' :
'-',
3198 (finfo->st_mode & S_IROTH) ?
'r' :
'-',
3199 (finfo->st_mode & S_IWOTH) ?
'w' :
'-',
3200 (finfo->st_mode & S_IXOTH) ?
'x' :
'-');
3223 c->SetStemArrayElement(treeData->
files, treeData->
count, t);
3224 c->ReleaseLocalReference(t);
3292 bool caseless = options &
CASELESS;
3296 dir_handle = opendir(path);
3297 if ( dir_handle == NULL )
3315 closedir(dir_handle);
3320 snprintf(treeData->
dFoundFile, len+1,
"%s%s", path, fileName);
3323 if ( !
formatFile(c, treeData, options, &finfo) )
3325 closedir(dir_handle);
3333 closedir(dir_handle);
3334 dir_handle = opendir(path);
3336 if ( dir_handle == NULL )
3347 if ( strcmp(fileName,
".") == 0 || strcmp(fileName,
"..") == 0 )
3358 closedir(dir_handle);
3363 snprintf(treeData->
dFoundFile, len+1,
"%s%s", path, fileName);
3366 if ( !
formatFile(c, treeData, options, &finfo) )
3368 closedir(dir_handle);
3377 closedir(dir_handle);
3378 dir_handle = opendir(path);
3379 if ( dir_handle == NULL )
3389 char *dTmpDirName = tmpDirName;
3393 if (
linFindNextDir(c,
"*", path, dir_handle, &finfo, &fileName, 0) )
3398 if ( strcmp(fileName,
".") == 0 || strcmp(fileName,
"..") == 0 )
3404 len = snprintf(dTmpDirName, nTmpDirName,
"%s%s/", path, fileName);
3405 if ( len >= (
int)nTmpDirName )
3409 closedir(dir_handle);
3414 snprintf(dTmpDirName, len+1,
"%s%s/", path, fileName);
3419 closedir(dir_handle);
3427 while (
linFindNextDir(c,
"*", path, dir_handle, &finfo, &fileName, 0) );
3436 closedir(dir_handle);
3448 treeData->
files = files;
3519 OPTIONAL_CSTRING, targetAttr, OPTIONAL_CSTRING,
newAttr)
3542 if ( !
getPath(context, fileSpec, &dPath, &nPath, &treeData) )
3563 context->SetStemArrayElement(treeData.
files, 0, context->WholeNumber(treeData.
count));
3613 args[0].strlength > 512)
3618 if (args[1].strlength != 1)
3620 filler = args[1].
strptr[0];
3625 dir = (
char*) malloc(args[0].strlength+1);
3631 strcpy(dir, args[0].strptr);
3637 for (x = 0; tmp[x] != 0; x++)
3639 if (tmp[x] == filler)
3655 snprintf(numstr,
sizeof numstr,
"%01u", (
int)num);
3658 snprintf(numstr,
sizeof numstr,
"%02u", (
int)num);
3661 snprintf(numstr,
sizeof numstr,
"%03u", (
int)num);
3664 snprintf(numstr,
sizeof numstr,
"%04u", (
int)num);
3667 snprintf(numstr,
sizeof numstr,
"%05u", (
int)num);
3673 for (x = 0; tmp[x] !=0; x++)
3675 if (tmp[x] == filler)
3677 tmp[x] = numstr[i++];
3687 while((*tmp !=
'/') && (*tmp !=
'\\') && (tmp > dir))
3696 array = tempnam(NULL,file);
3698 else if(*dir ==
'/'){
3700 array = tempnam(
"/",file);
3704 array = tempnam(NULL,file);
3711 array = tempnam(dir,file);
3714 if(strlen(array) > 255)
3716 free((
char *)retstr->
strptr);
3717 retstr->
strptr = (
char *) malloc(strlen(array) + 1);
3720 strcpy(retstr->
strptr, array);
3767 else if (((
size_t)pclass > 0) && ((
size_t)pclass <= 4)){
3773 priority = getpriority(PRIO_PROCESS, getpid());
3776 setpriority(PRIO_PROCESS, getpid(),-level);
3815 #if defined( HAVE_CATOPEN )
3819 const char default_message[] = {
"Error: Message catalog not open !\0"};
3821 const char not_found_message[] = {
"Error: Message not found !\0"};
3823 const char error_insertions[] = {
"Error: Unable to generate message \
3824 (wrong insertions)\0"};
3826 const char cat_not_found_message[] = {
"Error: Message catalog not found !\0"};
3831 const char * msgfile;
3836 if (numargs < 1 || numargs > 11 ||
3841 if (!
string2int(args[0].strptr, &msgnum) || msgnum < 0)
3848 msgfile = args[1].
strptr;
3852 #if defined( HAVE_SETLOCALE )
3853 setlocale(LC_ALL,
"en_US");
3856 #if defined( HAVE_CATOPEN )
3858 if((catalog = catopen(msgfile, NL_CAT_LOCALE)) == (nl_catd)-1){
3859 retstr->
strptr = (
char *)malloc(strlen(cat_not_found_message)+1);
3860 strcpy(retstr->
strptr, cat_not_found_message);
3861 retstr->
strlength = strlen(cat_not_found_message);
3866 msg = catgets(catalog, setnum, (
int)msgnum, default_message);
3869 msg = not_found_message;
3878 for(
int j=2; j < icount+2; j++)
3879 msg_length += args[j].strlength;
3880 msg_length += strlen(msg);
3881 msg_length -= icount*2;
3884 if(!(retstr->
strptr = (
char *)malloc(msg_length+100))){
3891 temp =
const_cast<char *
>(msg);
3893 while((temp = strstr(temp,
"&"))){
3894 if(isdigit(*(temp+1))){
3903 temp =
const_cast<char *
>(msg);
3904 while((temp = strstr(temp,
"%s"))){
3915 strcpy(retstr->
strptr, error_insertions);
3920 args[3].
strptr) != msg_length)
3921 strcpy(retstr->
strptr, error_insertions);
3927 args[4].
strptr) != msg_length)
3928 strcpy(retstr->
strptr, error_insertions);
3935 args[5].
strptr) != msg_length)
3936 strcpy(retstr->
strptr, error_insertions);
3944 args[6].
strptr) != msg_length)
3945 strcpy(retstr->
strptr, error_insertions);
3954 args[7].
strptr) != msg_length)
3955 strcpy(retstr->
strptr, error_insertions);
3965 args[8].
strptr) != msg_length)
3966 strcpy(retstr->
strptr, error_insertions);
3977 args[9].
strptr) != msg_length)
3978 strcpy(retstr->
strptr, error_insertions);
3990 args[10].
strptr) != msg_length)
3991 strcpy(retstr->
strptr, error_insertions);
3995 strcpy(retstr->
strptr, error_insertions);
3999 strcpy(retstr->
strptr, msg);
4009 const char cat_not_supported_message[] = {
"Error: Message catalog (catopen) not supported !\0"};
4011 retstr->
strptr = (
char *)malloc(strlen(cat_not_supported_message)+1);
4012 strcpy(retstr->
strptr, cat_not_supported_message);
4013 retstr->
strlength = strlen(cat_not_supported_message);
4042 #if defined( HAVE_CATOPEN )
4046 const char default_message[] = {
"Error: Message catalog not open !\0"};
4048 const char not_found_message[] = {
"Error: Message not found !\0"};
4050 const char error_insertions[] = {
"Error: Unable to generate message \
4051 (wrong insertions)\0"};
4053 const char cat_not_found_message[] = {
"Error: Message catalog not found !\0"};
4058 const char * msgfile;
4063 if (numargs < 1 || numargs > 12 ||
4069 if (!
string2int(args[0].strptr, &setnum) || setnum < 0)
4073 if (!
string2int(args[1].strptr, &msgnum) || msgnum < 0)
4080 msgfile = args[2].
strptr;
4084 #if defined( HAVE_CATOPEN )
4086 if((catalog = catopen(msgfile, NL_CAT_LOCALE)) == (nl_catd)-1){
4087 retstr->
strptr = (
char *)malloc(strlen(cat_not_found_message)+1);
4088 strcpy(retstr->
strptr, cat_not_found_message);
4089 retstr->
strlength = strlen(cat_not_found_message);
4094 msg = catgets(catalog, setnum, msgnum, default_message);
4097 msg =
const_cast<char *
>(not_found_message);
4106 for(
int j=3; j < icount+3; j++)
4107 msg_length += args[j].strlength;
4108 msg_length += strlen(msg);
4109 msg_length -= icount*2;
4112 if(!(retstr->
strptr = (
char *)malloc(msg_length+100))){
4121 while((temp = strstr(temp,
"&"))){
4122 if(isdigit(*(temp+1))){
4131 while((temp = strstr(temp,
"%s"))){
4143 strcpy(retstr->
strptr, error_insertions);
4148 args[4].
strptr) != msg_length)
4149 strcpy(retstr->
strptr, error_insertions);
4155 args[5].
strptr) != msg_length)
4156 strcpy(retstr->
strptr, error_insertions);
4163 args[6].
strptr) != msg_length)
4164 strcpy(retstr->
strptr, error_insertions);
4172 args[7].
strptr) != msg_length)
4173 strcpy(retstr->
strptr, error_insertions);
4182 args[8].
strptr) != msg_length)
4183 strcpy(retstr->
strptr, error_insertions);
4193 args[9].
strptr) != msg_length)
4194 strcpy(retstr->
strptr, error_insertions);
4205 args[10].
strptr) != msg_length)
4206 strcpy(retstr->
strptr, error_insertions);
4218 args[11].
strptr) != msg_length)
4219 strcpy(retstr->
strptr, error_insertions);
4223 strcpy(retstr->
strptr, error_insertions);
4227 strcpy(retstr->
strptr, msg);
4237 const char cat_not_supported_message[] = {
"Error: Message catalog (catopen) not supported !\0"};
4239 retstr->
strptr = (
char *)malloc(strlen(cat_not_supported_message)+1);
4240 strcpy(retstr->
strptr, cat_not_supported_message);
4241 retstr->
strlength = strlen(cat_not_supported_message);
4268 if (!strcasecmp(args[0].strptr,
"NOECHO"))
4270 else if (strcasecmp(args[0].strptr,
"ECHO"))
4302 RXFUNCBLOCK *funcblock;
4303 PRXINITFUNCPKG InitFunc;
4310 argstring = args[0].
strptr;
4312 if ( (arglength == 0 ) ||
4314 (!strchr( argstring,
'/' )) )
4317 if (!(InitFunc = (PRXINITFUNCPKG)load(argstring,0,NULL)))
4319 if ( InitFunc == NULL ) {
4320 fprintf(stderr,
" *** Unable to load library %s !\nError message: errno = %d;",\
4322 perror(
" REXXUTIL");
4329 rc = (*InitFunc)(&funcblock);
4332 fprintf(stderr,
"*** Library load routine gave error %d.\n",rc);
4342 for (j=0; funcblock[j].name != NULL; j++) {
4344 fprintf(stderr,
"REXXUTIL: PKGFunction %s \n", funcblock[j].name);
4346 if ( funcblock[j].
function && (rc == NULL) ) {
4348 argstring, funcblock[j].name);
4361 return SysAddFuncPkg(
4389 RXFUNCBLOCK *funcblock;
4390 PRXINITFUNCPKG InitFunc;
4397 argstring = args[0].
strptr;
4399 if ( (arglength == 0 ) ||
4403 if (!(InitFunc = (PRXINITFUNCPKG)load(argstring,0,NULL)))
4405 if ( InitFunc == NULL ) {
4406 fprintf(stderr,
" *** Unable to drop library %s !\nError message: errno = %d;",\
4408 perror(
" REXXUTIL");
4415 rc = (*InitFunc)(&funcblock);
4418 fprintf(stderr,
" *** Library drop routine gave error %d.\n",rc);
4428 for (j=0; funcblock[j].name != NULL; j++) {
4430 fprintf(stderr,
"REXXUTIL: PKGFunction %s \n", funcblock[j].name);
4432 if ( funcblock[j].
function && (rc == NULL) ) {
4446 return SysDropFuncPkg(
4528 else if (args[0].strptr[0] ==
'b' || args[0].strptr[0] ==
'B')
4531 else if (args[0].strptr[0] ==
'n' || args[0].strptr[0] ==
'N')
4536 perror(
"*** ERROR: Creating pipe");
4542 iStatus = fcntl(iaH[0], F_GETFL, NULL);
4543 iStatus |= O_NONBLOCK;
4545 if (fcntl(iaH[0], F_SETFL, iStatus) == -1) {
4546 perror(
"*** ERROR: Setting NONBLOCK flag");
4547 close(iaH[0]); close(iaH[1]);
4574 bool fCloseFile =
false;
4576 if ( (numargs > 1) ||
4585 handle = open(args[0].strptr, O_WRONLY | O_APPEND | O_CREAT, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
4590 handle = STDOUT_FILENO;
4611 ignore = write(handle,
"Name=", strlen(
"Name="));
4612 ignore = write(handle, shvb.
shvname.strptr, shvb.
shvname.strlength);
4613 ignore = write(handle,
", Value='", 9);
4615 ignore = write(handle,
"'\n", 2);
4651 const char *dir_buf = NULL;
4653 bool alloc_Flag =
false;
4655 if ( (numargs < 1) || (numargs > 2) ||
4659 if(*(args[0].strptr) ==
'~')
4666 dir_buf = args[0].
strptr;
4669 if (stat64(dir_buf, &buf) < 0)
4678 switch (args[1].strptr[0])
4682 newtime = localtime(&(buf.st_atime));
4686 newtime = localtime(&(buf.st_mtime));
4694 newtime = localtime(&(buf.st_mtime));
4696 newtime->tm_year += 1900;
4697 newtime->tm_mon += 1;
4708 if( (dir_buf) && (alloc_Flag ==
true) )
4709 free((
void *)dir_buf);
4732 struct utimbuf timebuf;
4736 const char *dir_buf = NULL;
4737 bool alloc_Flag =
false;
4743 if ( (numargs < 1) || (numargs > 3) ||
4748 if(*(args[0].strptr) ==
'~')
4755 dir_buf = args[0].
strptr;
4758 if (stat64(dir_buf, &buf) < 0)
4766 timebuf.modtime = ltime;
4767 if (utime(dir_buf, &timebuf) < 0)
4774 newtime = localtime(&(buf.st_mtime));
4779 if (sscanf(args[1].strptr,
"%4d-%2d-%2d", &newtime->tm_year,
4780 &newtime->tm_mon, &newtime->tm_mday) != 3)
4782 newtime->tm_year -= 1900;
4783 newtime->tm_mon -= 1;
4788 if (sscanf(args[2].strptr,
"%2d:%2d:%2d", &newtime->tm_hour,
4789 &newtime->tm_min, &newtime->tm_sec) != 3)
4792 ltime = mktime(newtime);
4793 timebuf.modtime = ltime;
4794 if (utime(dir_buf, &timebuf) < 0)
4800 if( (dir_buf) && (alloc_Flag ==
true) )
4801 free((
void *)dir_buf);
4810 size_t start,
size_t end,
size_t firstcol,
size_t lastcol);
4835 size_t firstCol = 0;
4840 if ( (numargs < 1) || (numargs > 7) ||
4845 memset(stemName, 0,
sizeof(stemName));
4846 strcpy(stemName, args[0].strptr);
4847 if (stemName[args[0].strlength-1] !=
'.')
4853 switch (args[1].strptr[0])
4870 switch (args[2].strptr[0])
4913 if (lastCol < firstCol)
4919 if (!
RexxStemSort(stemName, sortOrder, sortType, first, last, firstCol, lastCol)) {
4954 RexxObjectPtr temp = context->GetStemArrayElement(toStem, 0);
4955 if (temp ==
NULLOBJECT || !context->StringSize(temp, &items))
4957 context->InvalidRoutine();
4962 if (start + count - 1 > items)
4964 context->InvalidRoutine();
4970 for ( index = start; index + count <= items; index++)
4973 RexxObjectPtr value = context->GetStemArrayElement(toStem, index + count);
4980 context->SetStemArrayElement(toStem, index, value);
4984 for (index = items - count + 1; index <= items; index++)
4986 context->DropStemArrayElement(toStem, index);
4989 context->SetStemArrayElement(toStem, 0, context->StringSize(items - count));
5011 RexxObjectPtr temp = context->GetStemArrayElement(toStem, 0);
5012 if (temp ==
NULLOBJECT || !context->StringSize(temp, &count))
5014 context->InvalidRoutine();
5019 if (position == 0 || (position > count + 1))
5021 context->InvalidRoutine();
5025 for (
size_t index = count; index >= position; index--)
5028 RexxObjectPtr value = context->GetStemArrayElement(toStem, index);
5035 context->SetStemArrayElement(toStem, index + 1, value);
5039 context->SetStemArrayElement(toStem, position, newValue);
5040 context->SetStemArrayElement(toStem, 0, context->WholeNumber(count + 1));
5063 OPTIONAL_stringsize_t, from, OPTIONAL_stringsize_t, to, OPTIONAL_stringsize_t, count,
5064 OPTIONAL_CSTRING, option)
5066 bool inserting =
false;
5083 context->InvalidRoutine();
5091 RexxObjectPtr temp = context->GetStemArrayElement(fromStem, 0);
5092 if (temp ==
NULLOBJECT || !context->StringSize(temp, &fromCount))
5094 context->InvalidRoutine();
5113 if ((count > (fromCount - from + 1)) || (fromCount == 0))
5115 context->InvalidRoutine();
5122 count = fromCount - from + 1;
5127 temp = context->GetStemArrayElement(toStem, 0);
5128 if (temp !=
NULLOBJECT && !context->StringSize(temp, &toCount))
5130 context->InvalidRoutine();
5135 if (to > toCount + 1)
5137 context->InvalidRoutine();
5144 for (
size_t index = toCount; index >= to; index--)
5147 RexxObjectPtr value = context->GetStemArrayElement(toStem, index);
5154 context->SetStemArrayElement(toStem, index + count, value);
5160 context->SetStemArrayElement(toStem, 0, context->StringSize(toCount));
5163 for (
size_t index = 0; index < count; index++)
5166 RexxObjectPtr value = context->GetStemArrayElement(fromStem, from + index);
5173 context->SetStemArrayElement(toStem, to + index, value);
5177 if (to + count - 1 > toCount)
5179 context->SetStemArrayElement(toStem, 0, context->StringSize(to + count - 1));
5204 unsigned int uiUsedCPUTime = 0;
5205 unsigned int uiUsedCPUmsec = 0;
5206 unsigned int uiUsedHours = 0;
5207 unsigned int uiUsedMinutes = 0;
5208 unsigned int uiUsedSeconds = 0;
5211 struct rusage struResUse;
5217 if ((numargs == 0) || (!strcasecmp(args[0].strptr,
"PID")))
5224 if (!strcasecmp(args[0].strptr,
"PPID"))
5231 if (!strcasecmp(args[0].strptr,
"PGID"))
5238 if (!strcasecmp(args[0].strptr,
"PPRIO"))
5248 iRc = getrusage ( RUSAGE_SELF, &struResUse);
5255 if (!strcasecmp(args[0].strptr,
"PTIME"))
5257 uiUsedCPUmsec = (
unsigned int) struResUse.ru_utime.tv_usec/1000;
5258 uiUsedCPUmsec += (
unsigned int) struResUse.ru_stime.tv_usec/1000;
5259 if (uiUsedCPUmsec >= 1000 )
5261 uiUsedCPUTime = uiUsedCPUmsec / 1000;
5262 uiUsedCPUmsec = uiUsedCPUmsec % 1000;
5264 uiUsedCPUTime += (
unsigned int) struResUse.ru_utime.tv_sec;
5265 uiUsedCPUTime += (
unsigned int) struResUse.ru_stime.tv_sec;
5266 uiUsedHours = uiUsedCPUTime / 3600;
5267 uiUsedMinutes = uiUsedCPUTime / 60;
5268 if (uiUsedMinutes >= 60 ) uiUsedMinutes = uiUsedMinutes % 60;
5269 if (uiUsedCPUTime >= 60 ) uiUsedSeconds = uiUsedCPUTime % 60;
5270 else uiUsedSeconds = uiUsedCPUTime;
5272 snprintf(retstr->
strptr,
DEFRXSTRING,
"CPU_Time Summary: %2d:%.2d:%.2d:%.3d Kernel:",
5273 uiUsedHours, uiUsedMinutes, uiUsedSeconds, uiUsedCPUmsec );
5275 uiUsedCPUmsec = (
unsigned int) struResUse.ru_stime.tv_usec/1000;
5276 uiUsedCPUTime = (
unsigned int) struResUse.ru_stime.tv_sec;
5277 uiUsedHours = uiUsedCPUTime / 3600;
5278 uiUsedMinutes = uiUsedCPUTime / 60;
5279 if (uiUsedMinutes >= 60 ) uiUsedMinutes = uiUsedMinutes % 60;
5280 if (uiUsedCPUTime >= 60 ) uiUsedSeconds = uiUsedCPUTime % 60;
5281 else uiUsedSeconds = uiUsedCPUTime;
5283 snprintf(timebuf,
sizeof timebuf,
" %2d:%.2d:%.2d:%.3d User:", uiUsedHours,
5284 uiUsedMinutes, uiUsedSeconds, uiUsedCPUmsec );
5285 strcat(retstr->
strptr, timebuf);
5287 uiUsedCPUmsec = (
unsigned int) struResUse.ru_utime.tv_usec/1000;
5288 uiUsedCPUTime = (
unsigned int) struResUse.ru_utime.tv_sec;
5289 uiUsedHours = uiUsedCPUTime / 3600;
5290 uiUsedMinutes = uiUsedCPUTime / 60;
5291 if (uiUsedMinutes >= 60 ) uiUsedMinutes = uiUsedMinutes % 60;
5292 if (uiUsedCPUTime >= 60 ) uiUsedSeconds = uiUsedCPUTime % 60;
5293 else uiUsedSeconds = uiUsedCPUTime;
5295 snprintf(timebuf,
sizeof timebuf,
" %2d:%.2d:%.2d:%.3d", uiUsedHours,
5296 uiUsedMinutes, uiUsedSeconds, uiUsedCPUmsec );
5297 strcat(retstr->
strptr, timebuf);
5303 if (!strcasecmp(args[0].strptr,
"PMEM"))
5305 snprintf(retstr->
strptr,
DEFRXSTRING,
"Max_Memory_RSS: %ld", struResUse.ru_maxrss);
5310 if (!strcasecmp(args[0].strptr,
"PSWAPS"))
5312 snprintf(retstr->
strptr,
DEFRXSTRING,
"Memory_swaps: %ld", struResUse.ru_nswap);
5317 if (!strcasecmp(args[0].strptr,
"PRCVDSIG"))
5319 snprintf(retstr->
strptr,
DEFRXSTRING,
"Received_signals: %ld", struResUse.ru_nsignals);
5341 char *errmsg = NULL;
5348 errnum = atoi(args[0].strptr);
5349 errmsg = strerror( errnum );
5350 if (errmsg == NULL )
5351 retstr->
strptr[0] =
'\0';
5354 if (strlen(errmsg) >= retstr->
strlength)
5355 retstr->
strptr = (
char *) malloc(strlen(errmsg + 1));
5356 strcpy(retstr->
strptr,errmsg);
5404 int close(
bool returnError=
true);
5412 int closeStatus = 0;
5437 operator char *()
const {
return value; }
5449 char actualpath1[PATH_MAX+1];
5450 char actualpath2[PATH_MAX+1];
5451 if (realpath(path1, actualpath1) == NULL)
return false;
5452 if (realpath(path2, actualpath2) == NULL)
return false;
5453 return strcmp(actualpath1, actualpath2) == 0;
5465 AutoFree filenameCopy = strdup(filename);
5466 if (filenameCopy != NULL)
5468 AutoFree directory = strdup(dirname(filenameCopy));
5469 if (directory != NULL)
5471 char *newFilename = tempnam(directory, NULL);
5472 if (newFilename != NULL)
return newFilename;
5488 if (timestampsPreserved != NULL) *timestampsPreserved =
false;
5489 if (modePreserved != NULL) *modePreserved =
false;
5491 if (
SamePaths(fromFile, toFile))
return EEXIST;
5493 struct stat64 fromStat;
5494 if (stat64(fromFile, &fromStat) == -1)
return errno;
5495 AutoClose fromHandle = open64(fromFile, O_RDONLY);
5496 if (fromHandle == -1)
return errno;
5498 struct stat64 toStat;
5499 bool toFileCreated = (stat64(toFile, &toStat) == -1);
5500 AutoClose toHandle = open64(toFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
5501 if (toHandle == -1)
return errno;
5506 int count = read(fromHandle, &buffer,
IBUF_LEN);
5507 if (count == -1)
return errno;
5508 if (count == 0)
break;
5509 if (write(toHandle, buffer, count) == -1)
return errno;
5512 if (fromHandle.
close() == -1)
return errno;
5513 if (toHandle.
close() == -1)
return errno;
5515 if (preserveTimestamps)
5517 struct utimbuf timebuf;
5518 timebuf.actime = fromStat.st_atime;
5519 timebuf.modtime = fromStat.st_mtime;
5520 if (utime(toFile, &timebuf) == 0)
5522 if (timestampsPreserved != NULL) *timestampsPreserved =
true;
5526 if (toFileCreated || preserveMode)
5528 if (chmod(toFile, fromStat.st_mode) == 0)
5530 if (modePreserved != NULL) *modePreserved =
true;
5544 if (timestampsPreserved != NULL) *timestampsPreserved =
false;
5545 if (modePreserved != NULL) *modePreserved =
false;
5547 if (
SamePaths(fromFile, toFile))
return EEXIST;
5549 struct stat64 fromStat;
5550 if (lstat64(fromFile, &fromStat) == -1)
return errno;
5551 bool fromFileIsSymbolicLink = S_ISLNK(fromStat.st_mode);
5553 struct stat64 toStat;
5554 bool toFileExists = (lstat64(toFile, &toStat) == 0);
5555 bool toFileIsSymbolicLink = (toFileExists && S_ISLNK(toStat.st_mode));
5558 if (toFileExists && (fromFileIsSymbolicLink || toFileIsSymbolicLink))
5563 if (force ==
false)
return EEXIST;
5566 if (errInfo != 0)
return errInfo;
5569 if (fromFileIsSymbolicLink)
5571 off_t pathSize = fromStat.st_size;
5572 AutoFree pathBuffer = (
char *)malloc(pathSize+1);
5573 if (pathBuffer == NULL)
return errno;
5574 if (readlink(fromFile, pathBuffer, pathSize) == -1)
return errno;
5575 pathBuffer[pathSize] =
'\0';
5576 if (toFileNewname != NULL && rename(toFile, toFileNewname) == -1)
return errno;
5577 if (symlink(pathBuffer, toFile) == -1)
5579 int errInfo = errno;
5581 if (toFileNewname != NULL) rename(toFileNewname, toFile);
5588 if (toFileNewname != NULL && rename(toFile, toFileNewname) == -1)
return errno;
5593 if (toFileNewname != NULL) rename(toFileNewname, toFile);
5598 if (toFileNewname != NULL) unlink(toFileNewname);
5624 if (
SamePaths(fromFile, toFile))
return EEXIST;
5625 if (rename(fromFile, toFile) == 0)
return 0;
5626 if (errno != EXDEV)
return errno;
5632 if (errInfo != 0)
return errInfo;
5633 if (rename(fromFile, fromFileNewname) == -1)
return errno;
5635 if (rename(fromFileNewname, fromFile) == -1)
return errno;
5640 if (copyStatus != 0)
return copyStatus;
5645 return unlink(fromFile);
5665 struct stat64 finfo;
5667 int rc = stat64(filename, &finfo);
5669 return rc == 0 && (S_ISREG(finfo.st_mode) || S_ISBLK(finfo.st_mode));
5684 struct stat64 finfo;
5686 int rc = stat64(filename, &finfo);
5687 return rc == 0 && S_ISDIR(finfo.st_mode);
5702 struct stat64 finfo;
5704 int rc = lstat64(filename, &finfo);
5705 return rc == 0 && S_ISLNK(finfo.st_mode);
5720 struct stat64 finfo;
5722 return stat64(filename, &finfo) == 0;
5726 #ifdef XX__cplusplus
RexxReturnCode RexxEntry RexxVariablePool(PSHVBLOCK pshvblock)
int close(bool returnError=true)
AutoClose & operator=(int fd)
AutoFree & operator=(char *p)
#define argumentExists(i)
#define REXX_INTERPRETER_4_0_0
#define REXX_CLASSIC_ROUTINE(n, e)
#define argumentOmitted(i)
#define REXX_LAST_ROUTINE()
#define REXX_TYPED_ROUTINE(n, e)
#define STANDARD_PACKAGE_HEADER
#define Rexx_Error_Invalid_argument_range
#define Rexx_Error_Incorrect_call_user_defined
#define Rexx_Error_Invalid_argument_number
#define Rexx_Error_System_service_user_defined
#define Rexx_Error_Incorrect_call_null
RexxReturnCode REXXENTRY RexxDeregisterFunction(CONSTANT_STRING)
RexxReturnCode REXXENTRY RexxLoadMacroSpace(size_t, CONSTANT_STRING *, CONSTANT_STRING)
RexxReturnCode REXXENTRY RexxAddMacro(CONSTANT_STRING, CONSTANT_STRING, size_t)
RexxReturnCode REXXENTRY RexxFreeMemory(void *)
struct _RexxStringObject * RexxStringObject
RexxReturnCode REXXENTRY RexxSaveMacroSpace(size_t, CONSTANT_STRING *, CONSTANT_STRING)
RexxReturnCode REXXENTRY RexxRegisterFunctionDll(CONSTANT_STRING, CONSTANT_STRING, CONSTANT_STRING)
RexxReturnCode REXXENTRY RexxQueryMacro(CONSTANT_STRING, unsigned short *)
struct _RexxObjectPtr * RexxObjectPtr
RexxReturnCode REXXENTRY RexxReorderMacro(CONSTANT_STRING, size_t)
RexxReturnCode REXXENTRY RexxClearMacroSpace(void)
RexxReturnCode REXXENTRY RexxDropMacro(CONSTANT_STRING)
struct _RexxStemObject * RexxStemObject
#define RXMACRO_SEARCH_BEFORE
#define RXMACRO_SEARCH_AFTER
CONSTANT_RXSTRING shvname
struct _SHVBLOCK * shvnext
RexxThreadContext * threadContext
char fileTime[FILETIME_BUF_LEN]
char fNameSpec[FNAMESPEC_BUF_LEN]
char foundFile[FOUNDFILE_BUF_LEN]
char foundFileLine[FOUNDFILELINE_BUF_LEN]
char fileAttr[FILEATTR_BUF_LEN]
size_t RexxEntry SysSearchPath(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
const char * mystrstr(const char *haystack, const char *needle, size_t hlen, size_t nlen, bool sensitive)
size_t RexxEntry SysVersion(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
int OpenFile(const char *file, GetFileData *filedata)
int CopyFile_DereferenceSymbolicLinks(CSTRING fromFile, CSTRING toFile, bool preserveTimestamps, bool preserveMode, bool *timestampsPreserved=NULL, bool *modePreserved=NULL)
bool string2size_t(const char *string, size_t *number)
#define BUILDRXSTRING(t, s)
RexxPackageEntry rexxutil_package_entry
OOREXX_GET_PACKAGE(rexxutil)
size_t RexxEntry SysCreatePipe(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
static void stringTooLongException(RexxThreadContext *c, CSTRING funcName, size_t pos, size_t len, size_t realLen)
RexxRoutine6(int, SysStemCopy, RexxStemObject, fromStem, RexxStemObject, toStem, OPTIONAL_stringsize_t, from, OPTIONAL_stringsize_t, to, OPTIONAL_stringsize_t, count, OPTIONAL_CSTRING, option)
size_t RexxEntry SysSetPriority(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
size_t RexxEntry SysWait(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
void uninitTreeData(RXTREEDATA *treeData)
size_t RexxEntry SysGetMessage(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
struct _GetFileData GetFileData
static bool getFileNameSegment(RexxCallContext *c, char *fileSpec, RXTREEDATA *treeData, int *lastSlashPos)
bool string2int(const char *string, int *number)
struct RxSemData RXSEMDATA
#define FNAMESPEC_BUF_LEN
RexxRoutineEntry rexxutil_routines[]
char typeOfEntry(mode_t m)
size_t RexxEntry SysDumpVariables(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
bool linFindNextFile(RexxCallContext *c, const char *fileSpec, const char *path, DIR *dir_handle, struct stat *finfo, char **d_name, bool caseless)
int get_next_path(char **ppenv, char *path_buf)
struct RxTreeData RXTREEDATA
int MoveFile(CSTRING fromFile, CSTRING toFile)
static void badSFTOptsException(RexxThreadContext *c, size_t pos, CSTRING actual)
size_t RexxEntry SysGetFileDateTime(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
static bool recursiveFindFile(RexxCallContext *c, const char *path, RXTREEDATA *treeData, uint32_t options)
void strupr(char *string)
int getkey(char *ret, bool echo)
size_t RexxEntry SysStemSort(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
size_t RexxEntry SysLoadFuncs(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
size_t neededSize(size_t need, size_t have)
size_t RexxEntry SysCls(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
bool linFindNextDir(RexxCallContext *c, const char *fileSpec, const char *path, DIR *dir_handle, struct stat *finfo, char **d_name, bool caseless)
#define FOUNDFILE_BUF_LEN
void CloseFile(GetFileData *filedata)
size_t RexxEntry SysGetErrortext(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
struct _SORT_MEM * PSORTMEM
struct RxStemData RXSTEMDATA
RexxRoutine0(int, SysClearRexxMacroSpace)
size_t RexxEntry SysDropFuncs(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
#define FOUNDFILELINE_BUF_LEN
static bool goodOpts(RexxCallContext *c, CSTRING opts, uint32_t *pOpts)
#define SORT_CASESENSITIVE
void nullStringException(RexxThreadContext *c, CSTRING fName, size_t pos)
size_t RexxEntry SysMkDir(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
RexxRoutine5(uint32_t, SysFileTree, CSTRING, fSpec, RexxStemObject, files, OPTIONAL_CSTRING, opts, OPTIONAL_CSTRING, targetAttr, OPTIONAL_CSTRING, newAttr)
size_t RexxEntry SysGetKey(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
size_t RexxEntry SysUtilVersion(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
size_t RexxEntry RexxStemSort(const char *stemname, int order, int type, size_t start, size_t end, size_t firstcol, size_t lastcol)
int CopyFile_DontDereferenceSymbolicLinks(CSTRING fromFile, CSTRING toFile, bool force, bool preserveTimestamps, bool preserveMode, bool *timestampsPreserved=NULL, bool *modePreserved=NULL)
size_t RexxEntry SysQueryProcess(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
char * TemporaryFilename(CSTRING filename, int &errInfo)
size_t RexxEntry SysFileSearch(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
int GetLine(char *line, size_t size, GetFileData *filedata)
bool isAcceptableFile(mode_t m)
RexxRoutine3(int, SysAddRexxMacro, CSTRING, name, CSTRING, file, OPTIONAL_CSTRING, option)
RexxRoutine1(int, SysSleep, RexxStringObject, delay)
int SearchPath(int SearchFlag, const char *path, const char *filename, char *buf, size_t buf_size)
#define CURRENT_DIR_FIRST
char * resolve_tilde(const char *)
static bool getPath(RexxCallContext *c, char *fileSpec, char **path, size_t *pathLen, RXTREEDATA *treeData)
bool formatFile(RexxCallContext *c, RXTREEDATA *treeData, uint32_t options, struct stat *finfo)
bool SamePaths(CSTRING path1, CSTRING path2)
static bool getFileSpecFromArg(RexxCallContext *context, CSTRING fSpec, char *fileSpec, size_t bufLen, size_t argPos)
static bool getBiggerBuffer(RexxCallContext *c, char **dPath, size_t *nPath, size_t nStaticBuffer)
void restore_terminal(int signal)
size_t RexxEntry SysSetFileDateTime(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
static bool getOptionsFromArg(RexxCallContext *context, CSTRING opts, uint32_t *options, size_t argPos)
size_t RexxEntry SysRmDir(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
size_t RexxEntry SysTempFileName(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
static bool increaseBuffer(RexxCallContext *c, size_t need, RXTREEDATA *treeData, TreeDataBuffers whichBuffer)
RexxRoutine2(int, SysReorderRexxMacro, CSTRING, name, CSTRING, option)
void outOfMemoryException(RexxThreadContext *c)
size_t RexxEntry SysFileDelete(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
size_t RexxEntry SysFork(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
void initTreeData(RXTREEDATA *treeData, RexxStemObject files)
static bool getPathSegment(RexxCallContext *c, char *fileSpec, char **path, size_t *pathLen, int lastSlashPos)
size_t RexxEntry SysGetMessageX(const char *name, size_t numargs, CONSTRXSTRING args[], const char *queuename, PRXSTRING retstr)
int ReadNextBuffer(GetFileData *filedata)
static uint32_t newAttr(int32_t *mask, uint32_t attr)