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 * ========================================================================
19 #include "../../pith/charconv/filesys.h"
20 #include "canaccess.h"
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.
44 last_cmpnt(char *filename
)
46 char *p
= NULL
, *q
= filename
;
51 while((q
= strchr(q
, FILE_SEP
)) != NULL
)
57 if(!p
&& isalpha((unsigned char) *filename
) && *(filename
+1) == ':' && *(filename
+2))
67 * Like our_mkdir but it makes subdirs as well as the final dir
70 our_mkpath(char *path
, mode_t mode
)
75 if(isalpha((unsigned char) q
[0]) && q
[1] == ':' && q
[2])
79 if(q
== path
&& q
[0] == FILE_SEP
)
82 while((q
= strchr(q
, FILE_SEP
)) != NULL
){
85 if(can_access(path
, ACCESS_EXISTS
) != 0)
86 if(our_mkdir(path
, mode
) != 0){
95 if(can_access(path
, ACCESS_EXISTS
) != 0 && our_mkdir(path
, mode
) != 0)