Differences From:
File
src/file.c
part of check-in
[b3ec774ab7]
- Fail with an error if a file is outside the checkout tree.
by
drh on
2008-02-08 16:24:24.
[view]
To:
File
src/file.c
part of check-in
[33c31f73cd]
- Record whether or not files have their execute permission bit set.
Set or clear the execute permission bit upon checkout.
by
drh on
2008-02-21 14:27:34.
Also file
src/file.c
part of check-in
[588bb7cd73]
- Merged to ed26056bb5.
by
aku on
2008-02-24 18:50:35.
[view]
@@ -66,8 +66,39 @@
return S_ISREG(buf.st_mode);
}
/*
+** Return TRUE if the named file is an executable. Return false
+** for directories, devices, fifos, symlinks, etc.
+*/
+int file_isexe(const char *zFilename){
+ struct stat buf;
+ if( stat(zFilename, &buf)!=0 ){
+ return 0;
+ }
+ return ((S_IXUSR|S_IXGRP|S_IXOTH)&buf.st_mode)!=0;
+}
+
+/*
+** Set or clear the execute bit on a file.
+*/
+void file_setexe(const char *zFilename, int onoff){
+#ifndef __MINGW32__
+ struct stat buf;
+ if( stat(zFilename, &buf)!=0 ) return;
+ if( onoff ){
+ if( (buf.st_mode & 0111)==0 ){
+ chmod(zFilename, buf.st_mode | 0111);
+ }
+ }else{
+ if( (buf.st_mode & 0111)!=0 ){
+ chmod(zFilename, buf.st_mode & ~0111);
+ }
+ }
+#endif
+}
+
+/*
** Return 1 if zFilename is a directory. Return 0 if zFilename
** does not exist. Return 2 if zFilename exists but is something
** other than a directory.
*/
@@ -76,22 +107,8 @@
if( stat(zFilename, &buf)!=0 ){
return 0;
}
return S_ISDIR(buf.st_mode) ? 1 : 2;
-}
-
-/*
-** Find both the size and modification time of a file. Return
-** the number of errors.
-*/
-int file_size_and_mtime(const char *zFilename, i64 *size, i64 *mtime){
- struct stat buf;
- if( stat(zFilename, &buf)!=0 ){
- return 1;
- }
- *size = buf.st_size;
- *mtime = buf.st_mtime;
- return 0;
}
/*
** Create the directory named in the argument, if it does not already