From: James Hammons Date: Thu, 29 Dec 2011 17:13:33 +0000 (+0000) Subject: Clean up of path_tail() function; now uses defined path delimiter. X-Git-Tag: v1.7.1~38 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rln;a=commitdiff_plain;h=741d94dd198fde4cfa058127a43e3071a47bd578 Clean up of path_tail() function; now uses defined path delimiter. --- diff --git a/rln.c b/rln.c index beb8c93..a27dde0 100644 --- a/rln.c +++ b/rln.c @@ -2043,10 +2043,12 @@ int dolist(void) // char * path_tail(char * name) { - char * temp = max(strrchr(name,'/'), max(strrchr(name,':'), strrchr(name, 92))); +// char * temp = MAX(strrchr(name, '/'), MAX(strrchr(name, ':'), strrchr(name, '\\'))); + char * temp = strrchr(name, PATH_DELIMITER); + // Return what was passed in if path delimiter was not found if (temp == NULL) - temp = (name - 1); + return name; return temp + 1; } @@ -2059,34 +2061,34 @@ int pladd(char * ptr, char * fname) { if (plist == NULL) { - plist = new_ofile(); // First time object record allocation - plast = plist; // Update last object record pointer + plist = new_ofile(); // First time object record allocation + plast = plist; // Update last object record pointer } else { - plast->o_next = new_ofile(); // Next object record allocation - plast = plast->o_next; // Update last object record pointer + plast->o_next = new_ofile(); // Next object record allocation + plast = plast->o_next; // Update last object record pointer } if (plast == NULL) { - printf("Out of memory.\n"); // Error if memory allocation fails + printf("Out of memory.\n"); // Error if memory allocation fails return 1; } - if (strlen(path_tail(fname)) > FNLEN-1) + if (strlen(path_tail(fname)) > FNLEN - 1) { // Error on excessive filename length printf("File name too long: %s (sorry!)\n",fname); return 1; } - strcpy(plast->o_name, path_tail(fname)); // Store filename, not path - *plast->o_arname = 0; // No archive name for this file - plast->o_image = ptr; // Store data pointer - plast->o_flags = O_USED; // File is used - plast->o_next = NULL; // Initialise next record pointer + strcpy(plast->o_name, path_tail(fname)); // Store filename, not path + *plast->o_arname = 0; // No archive name for this file + plast->o_image = ptr; // Store data pointer + plast->o_flags = O_USED; // File is used + plast->o_next = NULL; // Initialise next record pointer - return 0; // Return without errors + return 0; // Return without errors } diff --git a/rln.h b/rln.h index d4591b3..cec6409 100644 --- a/rln.h +++ b/rln.h @@ -16,7 +16,7 @@ #ifdef WIN32 //#define _OPEN_FLAGS _O_BINARY|_O_RDWR #define _OPEN_FLAGS _O_BINARY|_O_RDONLY -#define _BACKSLASH '\\' +#define PATH_DELIMITER '\\' #ifdef _MSC_VER #if _MSC_VER > 1000 #pragma warning(disable:4996) @@ -38,7 +38,7 @@ #ifdef __GCCUNIX__ //#define _OPEN_FLAGS O_RDWR #define _OPEN_FLAGS O_RDONLY -#define _BACKSLASH '/' +#define PATH_DELIMITER '/' #include #include #include @@ -68,9 +68,9 @@ #define warn(x, f) printf("Warning: repeated flag `%c'%s\n", x, f ? "; previous one(s) ignored." : ".") // Macro for max: good because longs, shorts, or pointers can be compared -#ifndef max -#define max(a,b) ((a) > (b) ? (a) : (b)) -#endif // max +#ifndef MAX +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif // Macro to swap the 16-bit words of a 32-bit integer #define _SWAPWORD(x) (((unsigned)(x) >> 16) | ((unsigned)(x) << 16))