* Implement a different way to delete a password from the cache.
[alpine.git] / pico / osdep / chkpoint.c
blob5d7860ee7746aecae2626e7bd8cb331063813ae1
1 /*
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 * ========================================================================
16 #include <system.h>
17 #include <general.h>
19 #include "../estruct.h"
20 #include "../mode.h"
21 #include "../pico.h"
22 #include "../edef.h"
23 #include "../efunc.h"
24 #include "../keydefs.h"
25 #include "filesys.h"
27 #include "../../pith/charconv/filesys.h"
29 #include "chkpoint.h"
33 * chkptinit -- initialize anything we need to support composer
34 * checkpointing
36 void
37 chkptinit(char *file, size_t filelen)
39 #ifndef _WINDOWS
40 unsigned pid;
41 char *chp;
42 #endif
44 if(!file[0]){
45 long gmode_save = gmode;
47 if(gmode&MDCURDIR)
48 gmode &= ~MDCURDIR; /* so fixpath will use home dir */
50 #ifndef _WINDOWS
51 strncpy(file, "#picoXXXXX#", filelen);
52 #else
53 strncpy(file, "#picoTM0.txt", filelen);
54 #endif
55 file[filelen-1] = '\0';
56 fixpath(file, filelen);
57 gmode = gmode_save;
59 else{
60 size_t l = strlen(file);
62 if(l+2 <= filelen && file[l-1] != C_FILESEP){
63 file[l++] = C_FILESEP;
64 file[l] = '\0';
67 #ifndef _WINDOWS
68 strncpy(file + l, "#picoXXXXX#", filelen-l);
69 #else
70 strncpy(file + l, "#picoTM0.txt", filelen-l);
71 #endif
72 file[filelen-1] = '\0';
75 #ifndef _WINDOWS
76 pid = (unsigned)getpid();
77 for(chp = file+strlen(file) - 2; *chp == 'X'; chp--){
78 *chp = (pid % 10) + '0';
79 pid /= 10;
81 #else
82 if(fexist(file, "r", (off_t *)NULL) == FIOSUC){ /* does file exist? */
83 char copy[NLINE];
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 */
90 #endif /* _WINDOWS */
92 our_unlink(file);