dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / gss_mechs / mech_krb5 / krb5 / os / krbfileio.c
blobe135b27aadcd17225704914c4e7710561b33c4b5
1 /*
2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
8 #include "k5-int.h"
9 #include <sys/file.h>
10 #include <fcntl.h>
12 #ifndef O_BINARY
13 #define O_BINARY 0
14 #endif
16 krb5_error_code
17 krb5_create_secure_file(krb5_context context, const char *pathname)
19 int fd;
20 int open_flag;
22 open_flag = O_CREAT|O_EXCL|O_TRUNC|O_RDWR;
25 * Make sure file name is reserved.
26 * The O_BINARY flag is not a supported flag in the Solaris
27 * open(2) system call, but it is included here to be consistent
28 * with other open calls in the Kerberos library code.
31 fd = open(pathname, open_flag | O_BINARY, 0600);
32 if (fd == -1) {
33 return (errno);
34 } else {
35 close(fd);
36 return (0);
40 krb5_error_code
41 krb5_sync_disk_file(krb5_context context, FILE *fp)
43 if (fp == NULL) {
44 (void) fclose(fp);
45 return (errno);
47 if ((fflush(fp) == EOF) || ferror(fp) || (fsync(fileno(fp)) == -1)) {
48 return (errno);
50 return (0);