* Implement a different way to delete a password from the cache.
[alpine.git] / pith / osdep / lstcmpnt.c
blob6615220780c95ecfb21b2e050e8661def72d1247
1 /*
2 * ========================================================================
3 * Copyright 2006-2008 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 * ========================================================================
15 #include <system.h>
16 #include <general.h>
18 #include <string.h>
19 #include "../../pith/charconv/filesys.h"
20 #include "canaccess.h"
21 #include "lstcmpnt.h"
24 #ifdef _WINDOWS
26 #define FILE_SEP '\\'
28 #else /* UNIX */
30 #define FILE_SEP '/'
32 #endif /* UNIX */
36 /*----------------------------------------------------------------------
37 Return pointer to last component of pathname.
39 Args: filename -- The pathname.
41 Result: Returned pointer points to last component in the input argument.
42 ----*/
43 char *
44 last_cmpnt(char *filename)
46 char *p = NULL, *q = filename;
48 if(filename == NULL)
49 return(filename);
51 while((q = strchr(q, FILE_SEP)) != NULL)
52 if(*++q)
53 p = q;
55 #ifdef _WINDOWS
57 if(!p && isalpha((unsigned char) *filename) && *(filename+1) == ':' && *(filename+2))
58 p = filename + 2;
60 #endif
62 return(p);
67 * Like our_mkdir but it makes subdirs as well as the final dir
69 int
70 our_mkpath(char *path, mode_t mode)
72 char save, *q = path;
74 #ifdef _WINDOWS
75 if(isalpha((unsigned char) q[0]) && q[1] == ':' && q[2])
76 q = path + 3;
77 #endif
79 if(q == path && q[0] == FILE_SEP)
80 q = path + 1;
82 while((q = strchr(q, FILE_SEP)) != NULL){
83 save = *q;
84 *q = '\0';
85 if(can_access(path, ACCESS_EXISTS) != 0)
86 if(our_mkdir(path, mode) != 0){
87 *q = save;
88 return -1;
91 *q = save;
92 q++;
95 if(can_access(path, ACCESS_EXISTS) != 0 && our_mkdir(path, mode) != 0)
96 return -1;
98 return 0;