Tidy: modernize-use-nullptr
[alexxy/gromacs.git] / src / gromacs / utility / futil.cpp
index 0b5fe92cfed5f0069e297426d027504229075e0d..e64440789ff750fdd930fae8b0e867b1c04ab2a8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -79,7 +79,7 @@ typedef struct t_pstack {
     struct t_pstack *prev;
 } t_pstack;
 
-static t_pstack    *pstack           = NULL;
+static t_pstack    *pstack           = nullptr;
 static bool         bUnbuffered      = false;
 static int          s_maxBackupCount = 0;
 
@@ -99,7 +99,7 @@ const DataFileFinder  g_defaultLibFileFinder;
 
 const DataFileFinder &getLibraryFileFinder()
 {
-    if (g_libFileFinder != NULL)
+    if (g_libFileFinder != nullptr)
     {
         return *g_libFileFinder;
     }
@@ -123,10 +123,10 @@ void gmx_set_max_backup_count(int count)
     if (count < 0)
     {
         const char *env = getenv("GMX_MAXBACKUP");
-        if (env != NULL)
+        if (env != nullptr)
         {
             // TODO: Check that the value is converted properly.
-            count = strtol(env, NULL, 10);
+            count = strtol(env, nullptr, 10);
             if (count < 0)
             {
                 count = 0;
@@ -194,16 +194,16 @@ int gmx_ffclose(FILE *fp)
     tMPI_Thread_mutex_lock(&pstack_mutex);
 
     ps = pstack;
-    if (ps == NULL)
+    if (ps == nullptr)
     {
-        if (fp != NULL)
+        if (fp != nullptr)
         {
             ret = fclose(fp);
         }
     }
     else if (ps->fp == fp)
     {
-        if (fp != NULL)
+        if (fp != nullptr)
         {
             ret = pclose(fp);
         }
@@ -212,13 +212,13 @@ int gmx_ffclose(FILE *fp)
     }
     else
     {
-        while ((ps->prev != NULL) && (ps->prev->fp != fp))
+        while ((ps->prev != nullptr) && (ps->prev->fp != fp))
         {
             ps = ps->prev;
         }
-        if ((ps->prev != NULL) && ps->prev->fp == fp)
+        if ((ps->prev != nullptr) && ps->prev->fp == fp)
         {
-            if (ps->prev->fp != NULL)
+            if (ps->prev->fp != nullptr)
             {
                 ret = pclose(ps->prev->fp);
             }
@@ -228,7 +228,7 @@ int gmx_ffclose(FILE *fp)
         }
         else
         {
-            if (fp != NULL)
+            if (fp != nullptr)
             {
                 ret = fclose(fp);
             }
@@ -246,7 +246,7 @@ void frewind(FILE *fp)
     tMPI_Thread_mutex_lock(&pstack_mutex);
 
     t_pstack *ps = pstack;
-    while (ps != NULL)
+    while (ps != nullptr)
     {
         if (ps->fp == fp)
         {
@@ -317,7 +317,7 @@ static FILE *uncompress(const char *fn, const char *mode)
 
     sprintf(buf, "uncompress -c < %s", fn);
     fprintf(stderr, "Going to execute '%s'\n", buf);
-    if ((fp = popen(buf, mode)) == NULL)
+    if ((fp = popen(buf, mode)) == nullptr)
     {
         gmx_open(fn);
     }
@@ -333,7 +333,7 @@ static FILE *gunzip(const char *fn, const char *mode)
 
     sprintf(buf, "gunzip -c < %s", fn);
     fprintf(stderr, "Going to execute '%s'\n", buf);
-    if ((fp = popen(buf, mode)) == NULL)
+    if ((fp = popen(buf, mode)) == nullptr)
     {
         gmx_open(fn);
     }
@@ -346,12 +346,12 @@ gmx_bool gmx_fexist(const char *fname)
 {
     FILE *test;
 
-    if (fname == NULL)
+    if (fname == nullptr)
     {
         return FALSE;
     }
     test = fopen(fname, "r");
-    if (test == NULL)
+    if (test == nullptr)
     {
         /*Windows doesn't allow fopen of directory - so we need to check this seperately */
         #if GMX_NATIVE_WINDOWS
@@ -445,14 +445,14 @@ FILE *gmx_ffopen(const char *file, const char *mode)
 #ifdef SKIP_FFOPS
     return fopen(file, mode);
 #else
-    FILE    *ff = NULL;
-    char     buf[256], *bufsize = 0, *ptr;
+    FILE    *ff = nullptr;
+    char     buf[256], *bufsize = nullptr, *ptr;
     gmx_bool bRead;
     int      bs;
 
-    if (file == NULL)
+    if (file == nullptr)
     {
-        return NULL;
+        return nullptr;
     }
 
     if (mode[0] == 'w')
@@ -465,7 +465,7 @@ FILE *gmx_ffopen(const char *file, const char *mode)
     strcpy(buf, file);
     if (!bRead || gmx_fexist(buf))
     {
-        if ((ff = fopen(buf, mode)) == NULL)
+        if ((ff = fopen(buf, mode)) == nullptr)
         {
             gmx_file(buf);
         }
@@ -473,7 +473,7 @@ FILE *gmx_ffopen(const char *file, const char *mode)
         /* Check whether we should be using buffering (default) or not
          * (for debugging)
          */
-        if (bUnbuffered || ((bufsize = getenv("GMX_LOG_BUFFER")) != NULL))
+        if (bUnbuffered || ((bufsize = getenv("GMX_LOG_BUFFER")) != nullptr))
         {
             /* Check whether to use completely unbuffered */
             if (bUnbuffered)
@@ -482,11 +482,11 @@ FILE *gmx_ffopen(const char *file, const char *mode)
             }
             else
             {
-                bs = strtol(bufsize, NULL, 10);
+                bs = strtol(bufsize, nullptr, 10);
             }
             if (bs <= 0)
             {
-                setbuf(ff, NULL);
+                setbuf(ff, nullptr);
             }
             else
             {
@@ -539,7 +539,7 @@ char *low_gmxlibfn(const char *file, gmx_bool bAddCWD, gmx_bool bFatal)
         }
     }
     GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
-    return NULL;
+    return nullptr;
 }
 
 FILE *low_libopen(const char *file, gmx_bool bFatal)
@@ -554,7 +554,7 @@ FILE *low_libopen(const char *file, gmx_bool bFatal)
         return fp;
     }
     GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
-    return NULL;
+    return nullptr;
 }
 
 char *gmxlibfn(const char *file)
@@ -610,7 +610,7 @@ void gmx_tmpnam(char *buf)
 FILE *gmx_fopen_temporary(char *buf)
 {
     int   i, len;
-    FILE *fpout = NULL;
+    FILE *fpout = nullptr;
 
     if ((len = strlen(buf)) < 7)
     {
@@ -642,7 +642,7 @@ FILE *gmx_fopen_temporary(char *buf)
         gmx_fatal(FARGS, "Error creating temporary file %s: %s", buf,
                   strerror(errno));
     }
-    if ((fpout = fdopen(fd, "w")) == NULL)
+    if ((fpout = fdopen(fd, "w")) == nullptr)
     {
         gmx_fatal(FARGS, "Cannot open temporary file %s", buf);
     }
@@ -674,8 +674,8 @@ int gmx_file_copy(const char *oldname, const char *newname, gmx_bool copy_if_emp
 {
 /* the full copy buffer size: */
 #define FILECOPY_BUFSIZE (1<<16)
-    FILE *in  = NULL;
-    FILE *out = NULL;
+    FILE *in  = nullptr;
+    FILE *out = nullptr;
     char *buf;
 
     snew(buf, FILECOPY_BUFSIZE);
@@ -819,7 +819,7 @@ void gmx_getcwd(char *buffer, size_t size)
 #else
     char *pdum = getcwd(buffer, size);
 #endif
-    if (pdum == NULL)
+    if (pdum == nullptr)
     {
         gmx_fatal(FARGS, "Cannot get working directory. Reason: %s",
                   strerror(errno));