diff options
| author | Ken Raeburn <raeburn@mit.edu> | 2002-12-31 09:21:12 +0000 |
|---|---|---|
| committer | Ken Raeburn <raeburn@mit.edu> | 2002-12-31 09:21:12 +0000 |
| commit | 279dfdc141bb3fc23c8fe25ea133c021b3a586ac (patch) | |
| tree | d1945398b4cdb2809664d5aa527cfe5059c5bb7f /src/util/profile/prof_file.c | |
| parent | e33427c7b4b006b206719bc9256c55d20860d1ec (diff) | |
| download | krb5-279dfdc141bb3fc23c8fe25ea133c021b3a586ac.tar.gz krb5-279dfdc141bb3fc23c8fe25ea133c021b3a586ac.tar.xz krb5-279dfdc141bb3fc23c8fe25ea133c021b3a586ac.zip | |
Merge some Mac-specific changes from meeroh's branch:
* profile.hin: Don't test MACINTOSH any more. On Mac OS X, include
TargetConditionals.h, set some pragmas, define COPY_RESOURCE_FORK, and error
out if TARGET_RT_MAC_CFM is defined; don't set the old m68k CFM pragmas.
Always use PROFILE_USES_PATHS code, don't test or define it.
(FSp_profile_init, FSp_profile_init_path): Declare, on Mac OS X.
* prof_int.h (NO_SYS_TYPES_H, NO_SYS_STAT_H) [macintosh]: Don't define these.
* prof_file.c: Always inclued sys/types.h and sys/stat.h.
(GetMacOSTempFilespec): Deleted.
(profile_flush_file_data) [COPY_RESOURCE_FORK]: Copy Mac resource fork from old
file to new before renaming.
(rw_access, profile_update_file_data, profile_flush_file_data,
profile_free_file_data): Assume PROFILE_USES_PATHS, don't test.
* prof_init.c (profile_ser_size, profile_ser_externalize,
profile_ser_internalize): Likewise.
(FSp_profile_init, FSp_profile_init_path): Define, on MacOS X.
* profile.exp: Add FSp_* functions.
* prof_file.c (r_access): New function.
(profile_open_file): Use it.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15073 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util/profile/prof_file.c')
| -rw-r--r-- | src/util/profile/prof_file.c | 105 |
1 files changed, 43 insertions, 62 deletions
diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index d2022da35..749a7550d 100644 --- a/src/util/profile/prof_file.c +++ b/src/util/profile/prof_file.c @@ -13,12 +13,8 @@ #include "prof_int.h" -#ifndef NO_SYS_TYPES_H #include <sys/types.h> -#endif -#ifndef NO_SYS_STAT_H #include <sys/stat.h> -#endif #include <errno.h> @@ -34,14 +30,6 @@ struct global_shared_profile_data krb5int_profile_shared_data = { }; #endif -#ifndef PROFILE_USES_PATHS -#include <FSp_fopen.h> - -static OSErr GetMacOSTempFilespec ( - const FSSpec* inFilespec, - FSSpec* outFilespec); -#endif - static void profile_free_file_data(prf_data_t); static int rw_access(filespec) @@ -60,11 +48,32 @@ static int rw_access(filespec) */ FILE *f; -#ifdef PROFILE_USES_PATHS f = fopen(filespec, "r+"); -#else - f = FSp_fopen(&filespec, "r+"); + if (f) { + fclose(f); + return 1; + } + return 0; #endif +} + +static int r_access(filespec) + profile_filespec_t filespec; +{ +#ifdef HAVE_ACCESS + if (access(filespec, R_OK) == 0) + return 1; + else + return 0; +#else + /* + * We're on a substandard OS that doesn't support access. So + * we kludge a test using stdio routines, and hope fopen + * checks the r/w permissions. + */ + FILE *f; + + f = fopen(filespec, "r"); if (f) { fclose(f); return 1; @@ -94,7 +103,7 @@ errcode_t profile_open_file(filespec, ret_prof) for (data = g_shared_trees; data; data = data->next) { if (!strcmp(data->filespec, filespec) /* Check that current uid has read access. */ - && access(data->filespec, R_OK) == 0) + && r_access(data->filespec) == 0) break; } if (data) { @@ -187,11 +196,7 @@ errcode_t profile_update_file_data(prf_data_t data) return 0; #endif errno = 0; -#ifdef PROFILE_USES_PATHS f = fopen(data->filespec, "r"); -#else - f = FSp_fopen (&data->filespec, "r"); -#endif if (f == NULL) { retval = errno; if (retval == 0) @@ -212,24 +217,6 @@ errcode_t profile_update_file_data(prf_data_t data) return 0; } -#ifndef PROFILE_USES_PATHS -OSErr GetMacOSTempFilespec ( - const FSSpec* inFileSpec, - FSSpec* outFileSpec) -{ - OSErr err; - - err = FindFolder (inFileSpec -> vRefNum, kTemporaryFolderType, - kCreateFolder, &(outFileSpec -> vRefNum), &(outFileSpec -> parID)); - if (err != noErr) - return err; - - BlockMoveData (&(inFileSpec -> name), &(outFileSpec -> name), StrLength (inFileSpec -> name) + 1); - return noErr; -} -#endif - - errcode_t profile_flush_file_data(data) prf_data_t data; { @@ -246,7 +233,6 @@ errcode_t profile_flush_file_data(data) retval = ENOMEM; -#ifdef PROFILE_USES_PATHS new_file = old_file = 0; new_file = malloc(strlen(data->filespec) + 5); if (!new_file) @@ -261,13 +247,6 @@ errcode_t profile_flush_file_data(data) errno = 0; f = fopen(new_file, "w"); -#else - /* On MacOS, we do this by writing to a new file and then atomically - swapping the files with a file system call */ - GetMacOSTempFilespec (&data->filespec, &new_file); - f = FSp_fopen (&new_file, "w"); -#endif - if (!f) { retval = errno; if (retval == 0) @@ -281,7 +260,24 @@ errcode_t profile_flush_file_data(data) goto errout; } -#ifdef PROFILE_USES_PATHS +#ifdef COPY_RESOURCE_FORK + { + FSSpec from; + FSSpec to; + OSErr err = FSpLocationFromFullPOSIXPath (data -> filespec, &from); + if (err == noErr) { + err = FSpLocationFromFullPOSIXPath (new_file, &to); + } + if (err == noErr) { + err = FSpResourceForkCopy (&from, &to); + } + if (err != noErr) { + retval = ENOENT; + goto end; + } + } +#endif + unlink(old_file); if (rename(data->filespec, old_file)) { retval = errno; @@ -292,17 +288,6 @@ errcode_t profile_flush_file_data(data) rename(old_file, data->filespec); /* back out... */ goto errout; } -#else - { - OSErr err = FSpExchangeFiles (&data->filespec, &new_file); - if (err != noErr) { - retval = ENFILE; - goto errout; - } - FSpDelete (&new_file); - } -#endif - data->flags = 0; if (rw_access(data->filespec)) @@ -310,12 +295,10 @@ errcode_t profile_flush_file_data(data) retval = 0; errout: -#ifdef PROFILE_USES_PATHS if (new_file) free(new_file); if (old_file) free(old_file); -#endif return retval; } @@ -364,10 +347,8 @@ static void profile_free_file_data(data) } } #endif -#ifdef PROFILE_USES_PATHS if (data->filespec) free(data->filespec); -#endif if (data->root) profile_free_node(data->root); if (data->comment) |
