Add support for tab-completion when selecting by rule
[alpine.git] / pith / osdep / writ_dir.c
blob4d759226fa28e93cc874e0bee9e08489d874eaca
1 /*
2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006 University of Washington
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 "../charconv/utf8.h"
17 #include "../charconv/filesys.h"
18 #include "canaccess.h"
19 #include "writ_dir.h"
22 /*----------------------------------------------------------------------
23 Check to see if a directory exists and is writable by us
25 Args: dir -- directory name
27 Result: returns 0 if it exists and is writable
28 1 if it is a directory, but is not writable
29 2 if it is not a directory
30 3 it doesn't exist.
31 ----*/
32 int
33 is_writable_dir(char *dir)
35 struct stat sb;
37 if(our_stat(dir, &sb) < 0)
38 /*--- It doesn't exist ---*/
39 return(3);
41 if(!(sb.st_mode & S_IFDIR))
42 /*---- it's not a directory ---*/
43 return(2);
45 if(can_access(dir, 07))
46 return(1);
47 else
48 return(0);