]> andersk Git - moira.git/blobdiff - gen/util.c
fix filsys name check in register_user
[moira.git] / gen / util.c
index 153987c97fb71e850f81c6f2070c4605238ac1b2..5e5c728711b6aa56eaab95ded8edaac125da421f 100644 (file)
@@ -1,47 +1,18 @@
 /* $Header$
  *
  * Utility routines used by the SMS extraction programs.
+ *
+ *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
+ *  For copying and distribution information, please see the file
+ *  <mit-copyright.h>.
  */
 
 
+#include <mit-copyright.h>
 #include <stdio.h>
 #include <sys/time.h>
-
-char *malloc();
-
-
-/* Trim trailing spaces from a string by replacing one of them with a null.
- */
-
-trim(s)
-register char *s;
-{
-    register char *p;
-
-    for (p = s; *s; s++)
-      if (*s != ' ')
-       p = s;
-    if (p != s) {
-       if (*p == ' ')
-         *p = 0;
-       else
-         p[1] = 0;
-    }
-}
-
-
-/* return a "saved" copy of the string */
-
-char *strsave(s)
-register char *s;
-{
-    register char *r;
-
-    r = malloc(strlen(s) + 1);
-    strcpy(r, s);
-    return(r);
-}
-
+#include <sms.h>
+#include <sms_app.h>
 
 
 /* ingres_date_and_time: passed a unix time_t, returns a string that ingres
@@ -111,3 +82,46 @@ char *ingres_date(t)
        }
 }
 
+
+fix_file(targetfile)
+char *targetfile;
+{
+    char oldfile[64], filename[64];
+
+    sprintf(oldfile, "%s.old", targetfile);
+    sprintf(filename, "%s~", targetfile);
+    if (rename(targetfile, oldfile) == 0) {
+       if (rename(filename, targetfile) < 0) {
+           rename(oldfile, targetfile);
+           perror("Unable to install new file (rename failed)\n");
+           fprintf(stderr, "Filename = %s\n", targetfile);
+           exit(SMS_CCONFIG);
+       }
+    } else {
+       if (rename(filename, targetfile) < 0) {
+           perror("Unable to rename old file\n");
+           fprintf(stderr, "Filename = %s\n", targetfile);
+           exit(SMS_CCONFIG);
+       }
+    }
+    unlink(oldfile);
+}
+
+
+char *dequote(s)
+register char *s;
+{
+    char *last = s;
+
+    while (*s) {
+       if (*s == '"')
+         *s = '\'';
+       else if (*s != ' ')
+         last = s;
+       s++;
+    }
+    if (*last == ' ')
+      *last = '\0';
+    else
+      *(++last) = '\0';
+}
This page took 0.03634 seconds and 4 git commands to generate.