Manually sort some includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / utility / cstringutil.c
index 58f1c64129f068814acfe8d951a37b009f381439..85cbd41c0af55b776340fcaa385f24f2992ce70a 100644 (file)
  * the research papers on the package. Check out http://www.gromacs.org.
  */
 /* This file is completely threadsafe - keep it that way! */
-#include "cstringutil.h"
+#include "gmxpre.h"
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "cstringutil.h"
 
 #include <assert.h>
 #include <ctype.h>
@@ -49,6 +47,9 @@
 #include <time.h>
 
 #include <sys/types.h>
+
+#include "config.h"
+
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
 #include <unistd.h>
 #endif
 
-#include "gromacs/fileio/futil.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/basenetwork.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
 int continuing(char *s)
@@ -102,7 +103,7 @@ char *fgets2(char *line, int n, FILE *stream)
          * or because of n being too small.
          * Since both cases occur very infrequently, we can check for EOF.
          */
-        if (!gmx_eof(stream))
+        if (!feof(stream))
         {
             gmx_fatal(FARGS, "An input file contains a line longer than %d characters, while the buffer passed to fgets2 has size %d. The line starts with: '%20.20s'", n, n, line);
         }
@@ -192,20 +193,22 @@ void trim (char *str)
 char *
 gmx_ctime_r(const time_t *clock, char *buf, int n)
 {
-    char tmpbuf[STRLEN];
-
-#ifdef GMX_NATIVE_WINDOWS
+#ifdef _MSC_VER
     /* Windows */
-    ctime_s( tmpbuf, STRLEN, clock );
+    ctime_s( buf, n, clock );
+#elif defined(GMX_NATIVE_WINDOWS)
+    char *tmpbuf = ctime( clock );
+    strncpy(buf, tmpbuf, n-1);
+    buf[n-1] = '\0';
 #elif (defined(__sun))
     /*Solaris*/
-    ctime_r(clock, tmpbuf, n);
+    ctime_r(clock, buf, n);
 #else
+    char tmpbuf[STRLEN];
     ctime_r(clock, tmpbuf);
-#endif
     strncpy(buf, tmpbuf, n-1);
     buf[n-1] = '\0';
-
+#endif
     return buf;
 }
 
@@ -213,7 +216,7 @@ void nice_header (FILE *out, const char *fn)
 {
     const char    *unk = "onbekend";
     time_t         clock;
-    const char    *user = unk;
+    const char    *user;
     int            gh;
 #ifdef HAVE_PWD_H
     uid_t          uid;
@@ -238,8 +241,9 @@ void nice_header (FILE *out, const char *fn)
     /* pw returns null on error (e.g. compute nodes lack /etc/passwd) */
     user = pw ? pw->pw_name : unk;
 #else
-    uid = 0;
-    gh  = -1;
+    uid  = 0;
+    gh   = -1;
+    user = unk;
 #endif
 
     gmx_ctime_r(&clock, timebuf, STRLEN);
@@ -586,6 +590,12 @@ str_to_int64_t(const char *str, char **endptr)
 #endif
 }
 
+char *gmx_step_str(gmx_int64_t i, char *buf)
+{
+    sprintf(buf, "%"GMX_PRId64, i);
+    return buf;
+}
+
 void parse_digits_from_plain_string(const char *digitstring, int *ndigits, int **digitlist)
 {
     int i;