From: Laurent MAZET Date: Tue, 14 Jan 2025 17:13:47 +0000 (+0100) Subject: cleaning of win32/linux specific codes X-Git-Tag: v1.0~44 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=f71e0a11a7c3a2fb4e1413a7fbff8fccb355fc5c;p=fm.git cleaning of win32/linux specific codes --- diff --git a/fm.c b/fm.c index 88530d0..5422172 100644 --- a/fm.c +++ b/fm.c @@ -379,11 +379,7 @@ int main (int argc, char *argv[]) case ALT_N: /* new dir */ string = getwindow ("New directory", winscreen, MAXFNAME / 2, MAXFNAME, NULL); if (string) { -#ifdef WIN32 - if (mkdir (string) != 0) { -#else - if (mkdir (string, 0750) != 0) { -#endif + if (MKDIR (string) != 0) { msgwindow ("Can't create directory", winscreen, 0); getch (); } diff --git a/function.c b/function.c index 2750f8b..9282187 100644 --- a/function.c +++ b/function.c @@ -81,11 +81,7 @@ list_t *_addelement (list_t *list, char *dirname, char *filename, type_t type) char *name = newfilename (dirname, filename); struct stat sb; -#ifdef WIN32 - if (stat (name, &sb) == -1) { -#else /* Linux*/ - if (lstat (name, &sb) == -1) { -#endif + if (STAT (name, &sb) == -1) { VERBOSE (ERROR, fprintf (stderr, "can't stat file '%s'\n", name)); exit (1); } @@ -216,11 +212,7 @@ void getinfo (char *dirname, elem_t *elem) char *name = newfilename (dirname, elem->name); struct stat sb; -#ifdef WIN32 - if (stat (name, &sb) == -1) { -#else /* Linux*/ - if (lstat (name, &sb) == -1) { -#endif + if (STAT (name, &sb) == -1) { VERBOSE (ERROR, fprintf (stderr, "can't stat file '%s%s%s'\n", dirname, SEPARATOR, elem->name)); exit (1); } @@ -410,22 +402,14 @@ char *processcopy (char *dest, char *src) char *msg = NULL; struct stat sb; -#ifdef WIN32 - if (stat (src, &sb) == 0) { -#else /* Linux*/ - if (lstat (src, &sb) == 0) { -#endif + if (STAT (src, &sb) == 0) { if ((sb.st_mode & S_IFMT) == S_IFDIR) { char *basename = strrchr (src, *SEPARATOR); basename = (basename) ? basename + 1 : src; VERBOSE (DEBUG, fprintf (stderr, "basename '%s'\n", basename)); char *nextdest = strdupcat (dest, SEPARATOR, basename, NULL); VERBOSE (DEBUG, fprintf (stderr, "mkdir '%s'\n", nextdest)); -#ifdef WIN32 - if (mkdir (nextdest) != 0) { -#else - if (mkdir (nextdest, 0750) != 0) { -#endif + if (MKDIR (nextdest) != 0) { msg = strdupcat ("Can't create directory '", nextdest, "'", NULL); } else { DIR *dir = opendir (src); @@ -468,11 +452,7 @@ int processdelete (char *name) int rc = 0; struct stat sb; -#ifdef WIN32 - if (stat (name, &sb) == 0) { -#else /* Linux*/ - if (lstat (name, &sb) == 0) { -#endif + if (STAT (name, &sb) == 0) { if ((sb.st_mode & S_IFMT) == S_IFDIR) { DIR *dir = opendir (name); diff --git a/function.h b/function.h index 976ad62..9735d11 100644 --- a/function.h +++ b/function.h @@ -17,6 +17,14 @@ #define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) +#ifdef WIN32 +#define STAT(file, psb) stat (file, psb) +#define MKDIR(dir) mkdir (dir) +#else /* Linux */ +#define STAT(file, psb) lstat (file, psb) +#define MKDIR(dir) mkdir (dir, 0755) +#endif + int strmaxlen (char *str, char ch); char *strdupcat (char *init, ...);