cleaning of win32/linux specific codes
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Tue, 14 Jan 2025 17:13:47 +0000 (18:13 +0100)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Tue, 14 Jan 2025 17:13:47 +0000 (18:13 +0100)
fm.c
function.c
function.h

diff --git a/fm.c b/fm.c
index 88530d072faef71f363ed572d065322f0832072d..54221720ea02c021588a99640dc8b718da62f766 100644 (file)
--- 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 ();
                     }
index 2750f8b94458ee877769a5e01471aafb4b8614d2..92821874aa4b36bdbae71c0062234e3acd840bd7 100644 (file)
@@ -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);
 
index 976ad628096e26c6db586acb4001e7e5f692bcf7..9735d110df590e212596a58e381eee77980f0a21 100644 (file)
 
 #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, ...);