* Update configure script to remove the search for a linking tcl
[alpine.git] / pico / osdep / chkpoint.c
blobd8fcba367c591c8f8d5d940574a9cbdfa8420f2f
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: chkpoint.c 769 2007-10-24 00:15:40Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2006-2007 University of Washington
8 * Copyright 2013-2018 Eduardo Chappa
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
20 #include <system.h>
21 #include <general.h>
23 #include "../estruct.h"
24 #include "../mode.h"
25 #include "../pico.h"
26 #include "../edef.h"
27 #include "../efunc.h"
28 #include "../keydefs.h"
29 #include "filesys.h"
31 #include "../../pith/charconv/filesys.h"
33 #include "chkpoint.h"
37 * chkptinit -- initialize anything we need to support composer
38 * checkpointing
40 void
41 chkptinit(char *file, size_t filelen)
43 #ifndef _WINDOWS
44 unsigned pid;
45 char *chp;
46 #endif
48 if(!file[0]){
49 long gmode_save = gmode;
51 if(gmode&MDCURDIR)
52 gmode &= ~MDCURDIR; /* so fixpath will use home dir */
54 #ifndef _WINDOWS
55 strncpy(file, "#picoXXXXX#", filelen);
56 #else
57 strncpy(file, "#picoTM0.txt", filelen);
58 #endif
59 file[filelen-1] = '\0';
60 fixpath(file, filelen);
61 gmode = gmode_save;
63 else{
64 size_t l = strlen(file);
66 if(l+2 <= filelen && file[l-1] != C_FILESEP){
67 file[l++] = C_FILESEP;
68 file[l] = '\0';
71 #ifndef _WINDOWS
72 strncpy(file + l, "#picoXXXXX#", filelen-l);
73 #else
74 strncpy(file + l, "#picoTM0.txt", filelen-l);
75 #endif
76 file[filelen-1] = '\0';
79 #ifndef _WINDOWS
80 pid = (unsigned)getpid();
81 for(chp = file+strlen(file) - 2; *chp == 'X'; chp--){
82 *chp = (pid % 10) + '0';
83 pid /= 10;
85 #else
86 if(fexist(file, "r", (off_t *)NULL) == FIOSUC){ /* does file exist? */
87 char copy[NLINE];
89 strncpy(copy, "#picoTM1.txt", sizeof(copy));
90 copy[sizeof(copy)-1] = '\0';
91 fixpath(copy, sizeof(copy));
92 our_rename(file, copy); /* save so we don't overwrite it */
94 #endif /* _WINDOWS */
96 our_unlink(file);