* Fixes and improvements to documentation contributed by Dennis Davis.
[alpine.git] / pith / osdep / writ_dir.c
blobc384e0584e44336e52fb78bc9d694617b13754f6
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: writ_dir.c 761 2007-10-23 22:35:18Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2013-2020 Eduardo Chappa
8 * Copyright 2006 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 #include <system.h>
20 #include "../charconv/utf8.h"
21 #include "../charconv/filesys.h"
22 #include "canaccess.h"
23 #include "writ_dir.h"
26 /*----------------------------------------------------------------------
27 Check to see if a directory exists and is writable by us
29 Args: dir -- directory name
31 Result: returns 0 if it exists and is writable
32 1 if it is a directory, but is not writable
33 2 if it is not a directory
34 3 it doesn't exist.
35 ----*/
36 int
37 is_writable_dir(char *dir)
39 struct stat sb;
41 if(our_stat(dir, &sb) < 0)
42 /*--- It doesn't exist ---*/
43 return(3);
45 if(!(sb.st_mode & S_IFDIR))
46 /*---- it's not a directory ---*/
47 return(2);
49 if(can_access(dir, 07))
50 return(1);
51 else
52 return(0);