2 * ========================================================================
3 * Copyright 2006-2007 University of Washington
4 * Copyright 2013-2022 Eduardo Chappa
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
19 #include "../estruct.h"
24 #include "../keydefs.h"
27 #include "../../pith/charconv/filesys.h"
33 * chkptinit -- initialize anything we need to support composer
37 chkptinit(char *file
, size_t filelen
)
45 long gmode_save
= gmode
;
48 gmode
&= ~MDCURDIR
; /* so fixpath will use home dir */
51 strncpy(file
, "#picoXXXXX#", filelen
);
53 strncpy(file
, "#picoTM0.txt", filelen
);
55 file
[filelen
-1] = '\0';
56 fixpath(file
, filelen
);
60 size_t l
= strlen(file
);
62 if(l
+2 <= filelen
&& file
[l
-1] != C_FILESEP
){
63 file
[l
++] = C_FILESEP
;
68 strncpy(file
+ l
, "#picoXXXXX#", filelen
-l
);
70 strncpy(file
+ l
, "#picoTM0.txt", filelen
-l
);
72 file
[filelen
-1] = '\0';
76 pid
= (unsigned)getpid();
77 for(chp
= file
+strlen(file
) - 2; *chp
== 'X'; chp
--){
78 *chp
= (pid
% 10) + '0';
82 if(fexist(file
, "r", (off_t
*)NULL
) == FIOSUC
){ /* does file exist? */
85 strncpy(copy
, "#picoTM1.txt", sizeof(copy
));
86 copy
[sizeof(copy
)-1] = '\0';
87 fixpath(copy
, sizeof(copy
));
88 our_rename(file
, copy
); /* save so we don't overwrite it */