]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/info.c
info: Use S_ISREG() instead of S_IFREG for readability
[empserver] / src / lib / commands / info.c
index 38e5419677085943e5708ca41a8484a779f9c810..961ad606b4c93c330d5783f15bd1effd644ca36e 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
@@ -42,6 +41,7 @@
 #include <sys/stat.h>
 #include <stdio.h>
 #if !defined(_WIN32)
+#include <strings.h>
 #include <dirent.h>
 #endif
 #include "commands.h"
@@ -92,7 +92,7 @@ info(void)
     snprintf(filename, sizeof(filename), "%s/%s", infodir, name);
     fp = fopen(filename, "r");
     if (fp == NULL) {
-       /* may be a "partial" request.  */
+       /* may be a "partial" request. */
        info_dp = opendir(infodir);
        if (!info_dp) {
            pr("Can't open info dir\n");
@@ -129,8 +129,7 @@ info(void)
            pr(".\n");
            return RET_FAIL;
        }
-       snprintf(filename, sizeof(filename), "%s/%s", infodir,
-                last);
+       snprintf(filename, sizeof(filename), "%s/%s", infodir, last);
        fp = fopen(filename, "r");
        if (fp == NULL) {
            pr("Error reading info file for %s\n", name);
@@ -146,7 +145,7 @@ info(void)
        fclose(fp);
        return RET_FAIL;
     }
-    if ((statb.st_mode & S_IFREG) == 0) {
+    if (!S_ISREG(statb.st_mode)) {
        pr("Error reading info file for %s\n", name);
        logerror("The info file \"%s\" is not regular file\n", filename);
        fclose(fp);
@@ -188,7 +187,7 @@ apro(void)
 
     info_dp = opendir(infodir);
     if (info_dp == NULL) {
-       pr("Can't open info dir \n");
+       pr("Can't open info dir\n");
        logerror("Can't open info dir \"%s\"", infodir);
        return RET_FAIL;
     }
@@ -210,8 +209,7 @@ apro(void)
     while ((dp = readdir(info_dp))) {
        if (dp->d_name[0] == '.')
            continue;
-       snprintf(filename, sizeof(filename), "%s/%s", infodir,
-                dp->d_name);
+       snprintf(filename, sizeof(filename), "%s/%s", infodir, dp->d_name);
        fp = fopen(filename, "r");
        alreadyhit = 0;
        nll = nlhl = 0;
@@ -222,7 +220,7 @@ apro(void)
                fclose(fp);
                continue;
            }
-           if ((statb.st_mode & S_IFREG) == 0) {
+           if (!S_ISREG(statb.st_mode)) {
                logerror("The info file \"%s\" is not regular file\n",
                         filename);
                fclose(fp);
@@ -303,7 +301,7 @@ info(void)
     snprintf(filename, sizeof(filename) - 1, "%s\\%s", infodir, name);
     fp = fopen(filename, "rb");
     if (fp == NULL) {
-       /* may be a "partial" request.  */
+       /* may be a "partial" request. */
        HANDLE hDir;
        WIN32_FIND_DATA fData;
        strcat(filename, "*");
@@ -320,7 +318,7 @@ info(void)
            default:
                pr("Error reading info dir\n");
                logerror("Error (%lu) reading info dir(%s)\\file(%s)",
-                   GetLastError(), infodir, filename);
+                        GetLastError(), infodir, filename);
            }
            return RET_FAIL;
        }
@@ -357,8 +355,7 @@ info(void)
            pr(".\n");
            return RET_FAIL;
        }
-       snprintf(filename, sizeof(filename), "%s/%s",
-                 infodir, last);
+       snprintf(filename, sizeof(filename), "%s/%s", infodir, last);
        fp = fopen(filename, "rb");
        if (fp == NULL) {
            pr("Error reading info file for %s\n", name);
@@ -412,7 +409,7 @@ apro(void)
            lhitlim = 100;
     }
 
-    snprintf(filename, sizeof(filename), "%s\\*",infodir);
+    snprintf(filename, sizeof(filename), "%s\\*", infodir);
     hDir = FindFirstFile(filename, &fData);
     if (hDir == INVALID_HANDLE_VALUE) {
        if (GetLastError() == ERROR_PATH_NOT_FOUND) {
@@ -421,7 +418,7 @@ apro(void)
        } else {
            pr("Error reading info dir\n");
            logerror("Error (%lu) reading info dir(%s)\\file(%s)",
-               GetLastError(), infodir, filename);
+                    GetLastError(), infodir, filename);
        }
        return RET_FAIL;
     }
@@ -446,7 +443,7 @@ apro(void)
             (fData.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE) ||
             (fData.dwFileAttributes == FILE_ATTRIBUTE_READONLY))) {
            snprintf(filename, sizeof(filename), "%s\\%s", infodir,
-                     fData.cFileName);
+                    fData.cFileName);
            fp = fopen(filename, "rb");
            alreadyhit = 0;
            nll = nlhl = 0;