diff options
Diffstat (limited to 'contrib/cvs/src/filesubr.c')
-rw-r--r-- | contrib/cvs/src/filesubr.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/contrib/cvs/src/filesubr.c b/contrib/cvs/src/filesubr.c index 5b9c076..381945d 100644 --- a/contrib/cvs/src/filesubr.c +++ b/contrib/cvs/src/filesubr.c @@ -52,7 +52,7 @@ copy_file (from, to) if (isdevice (from)) { -#if defined(HAVE_MKNOD) && defined(HAVE_ST_RDEV) +#if defined(HAVE_MKNOD) && defined(HAVE_STRUCT_STAT_ST_RDEV) if (stat (from, &sb) < 0) error (1, errno, "cannot stat %s", from); mknod (to, sb.st_mode, sb.st_rdev); @@ -216,7 +216,7 @@ isaccessible (file, mode) int umask = 0; int gmask = 0; int omask = 0; - int uid; + int uid, mask; if (stat(file, &sb) == -1) return 0; @@ -226,10 +226,11 @@ isaccessible (file, mode) uid = geteuid(); if (uid == 0) /* superuser */ { - if (mode & X_OK) - return sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH); - else + if (!(mode & X_OK) || (sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))) return 1; + + errno = EACCES; + return 0; } if (mode & R_OK) @@ -251,12 +252,11 @@ isaccessible (file, mode) omask |= S_IXOTH; } - if (sb.st_uid == uid) - return (sb.st_mode & umask) == umask; - else if (sb.st_gid == getegid()) - return (sb.st_mode & gmask) == gmask; - else - return (sb.st_mode & omask) == omask; + mask = sb.st_uid == uid ? umask : sb.st_gid == getegid() ? gmask : omask; + if ((sb.st_mode & mask) == mask) + return 1; + errno = EACCES; + return 0; #else return access(file, mode) == 0; #endif @@ -624,7 +624,7 @@ xcmp (file1, file2) numbers match. */ if (S_ISBLK (sb1.st_mode) || S_ISCHR (sb1.st_mode)) { -#ifdef HAVE_ST_RDEV +#ifdef HAVE_STRUCT_STAT_ST_RDEV if (sb1.st_rdev == sb2.st_rdev) return 0; else @@ -954,6 +954,26 @@ get_homedir () return home; } +/* Compose a path to a file in the home directory. This is necessary because + * of different behavior on UNIX and VMS. See the notes in vms/filesubr.c. + * + * A more clean solution would be something more along the lines of a + * "join a directory to a filename" kind of thing which was not specific to + * the homedir. This should aid portability between UNIX, Mac, Windows, VMS, + * and possibly others. This is already handled by Perl - it might be + * interesting to see how much of the code was written in C since Perl is under + * the GPL and the Artistic license - we might be able to use it. + */ +char * +strcat_filename_onto_homedir (dir, file) + const char *dir; + const char *file; +{ + char *path = xmalloc (strlen (dir) + 1 + strlen(file) + 1); + sprintf (path, "%s/%s", dir, file); + return path; +} + /* See cvs.h for description. On unix this does nothing, because the shell expands the wildcards. */ void @@ -1098,3 +1118,5 @@ fopen_case (name, mode, fp, pathp) return retval; } #endif /* SERVER_SUPPORT */ +/* vim:tabstop=8:shiftwidth=4 + */ |