summaryrefslogtreecommitdiff
path: root/pico/osdep/chkpoint.c
diff options
context:
space:
mode:
authorEduardo Chappa <echappa@gmx.com>2013-02-03 00:59:38 -0700
committerEduardo Chappa <echappa@gmx.com>2013-02-03 00:59:38 -0700
commit094ca96844842928810f14844413109fc6cdd890 (patch)
treee60efbb980f38ba9308ccb4fb2b77b87bbc115f3 /pico/osdep/chkpoint.c
downloadalpine-094ca96844842928810f14844413109fc6cdd890.tar.xz
Initial Alpine Version
Diffstat (limited to 'pico/osdep/chkpoint.c')
-rw-r--r--pico/osdep/chkpoint.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/pico/osdep/chkpoint.c b/pico/osdep/chkpoint.c
new file mode 100644
index 00000000..235cf83b
--- /dev/null
+++ b/pico/osdep/chkpoint.c
@@ -0,0 +1,98 @@
+#if !defined(lint) && !defined(DOS)
+static char rcsid[] = "$Id: chkpoint.c 769 2007-10-24 00:15:40Z hubert@u.washington.edu $";
+#endif
+
+/*
+ * ========================================================================
+ * Copyright 2006-2007 University of Washington
+ * Copyright 2013 Eduardo Chappa
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * ========================================================================
+ */
+
+
+#include <system.h>
+#include <general.h>
+
+#include "../estruct.h"
+#include "../mode.h"
+#include "../pico.h"
+#include "../edef.h"
+#include "../efunc.h"
+#include "../keydefs.h"
+#include "filesys.h"
+
+#include "../../pith/charconv/filesys.h"
+
+#include "chkpoint.h"
+
+
+/*
+ * chkptinit -- initialize anything we need to support composer
+ * checkpointing
+ */
+void
+chkptinit(char *file, size_t filelen)
+{
+#ifndef _WINDOWS
+ unsigned pid;
+ char *chp;
+#endif
+
+ if(!file[0]){
+ long gmode_save = gmode;
+
+ if(gmode&MDCURDIR)
+ gmode &= ~MDCURDIR; /* so fixpath will use home dir */
+
+#ifndef _WINDOWS
+ strncpy(file, "#picoXXXXX#", filelen);
+#else
+ strncpy(file, "#picoTM0.txt", filelen);
+#endif
+ file[filelen-1] = '\0';
+ fixpath(file, filelen);
+ gmode = gmode_save;
+ }
+ else{
+ size_t l = strlen(file);
+
+ if(l+2 <= filelen && file[l-1] != C_FILESEP){
+ file[l++] = C_FILESEP;
+ file[l] = '\0';
+ }
+
+#ifndef _WINDOWS
+ strncpy(file + l, "#picoXXXXX#", filelen-l);
+#else
+ strncpy(file + l, "#picoTM0.txt", filelen-l);
+#endif
+ file[filelen-1] = '\0';
+ }
+
+#ifndef _WINDOWS
+ pid = (unsigned)getpid();
+ for(chp = file+strlen(file) - 2; *chp == 'X'; chp--){
+ *chp = (pid % 10) + '0';
+ pid /= 10;
+ }
+#else
+ if(fexist(file, "r", (off_t *)NULL) == FIOSUC){ /* does file exist? */
+ char copy[NLINE];
+
+ strncpy(copy, "#picoTM1.txt", sizeof(copy));
+ copy[sizeof(copy)-1] = '\0';
+ fixpath(copy, sizeof(copy));
+ our_rename(file, copy); /* save so we don't overwrite it */
+ }
+#endif /* _WINDOWS */
+
+ our_unlink(file);
+}
+