1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: chkpoint.c 769 2007-10-24 00:15:40Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2006-2007 University of Washington
8 * Copyright 2013-2017 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 * ========================================================================
23 #include "../estruct.h"
28 #include "../keydefs.h"
31 #include "../../pith/charconv/filesys.h"
37 * chkptinit -- initialize anything we need to support composer
41 chkptinit(char *file
, size_t filelen
)
49 long gmode_save
= gmode
;
52 gmode
&= ~MDCURDIR
; /* so fixpath will use home dir */
55 strncpy(file
, "#picoXXXXX#", filelen
);
57 strncpy(file
, "#picoTM0.txt", filelen
);
59 file
[filelen
-1] = '\0';
60 fixpath(file
, filelen
);
64 size_t l
= strlen(file
);
66 if(l
+2 <= filelen
&& file
[l
-1] != C_FILESEP
){
67 file
[l
++] = C_FILESEP
;
72 strncpy(file
+ l
, "#picoXXXXX#", filelen
-l
);
74 strncpy(file
+ l
, "#picoTM0.txt", filelen
-l
);
76 file
[filelen
-1] = '\0';
80 pid
= (unsigned)getpid();
81 for(chp
= file
+strlen(file
) - 2; *chp
== 'X'; chp
--){
82 *chp
= (pid
% 10) + '0';
86 if(fexist(file
, "r", (off_t
*)NULL
) == FIOSUC
){ /* does file exist? */
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 */