X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcfileutil.c;h=23d2c17c12901a0e1c9b56886bc3bdc172ba88d4;hb=c257b555225193e54d85daf541d29578b3c93882;hp=7d2d14757281af64b6f1e7ae737fa72ed1cd7fe6;hpb=c5bfb6bb86ad457a4e85fc0a3b9a608313fe9e2a;p=silc.git diff --git a/lib/silcutil/silcfileutil.c b/lib/silcutil/silcfileutil.c index 7d2d1475..23d2c17c 100644 --- a/lib/silcutil/silcfileutil.c +++ b/lib/silcutil/silcfileutil.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2002 Pekka Riikonen + Copyright (C) 1997 - 2003 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -65,8 +65,13 @@ int silc_file_writefile(const char *filename, const char *buffer, SilcUInt32 len) { int fd; + int flags = O_CREAT | O_WRONLY | O_TRUNC; - if ((fd = creat(filename, 0644)) == -1) { +#if defined(O_BINARY) + flags |= O_BINARY; +#endif /* O_BINARY */ + + if ((fd = open(filename, flags, 0644)) == -1) { SILC_LOG_ERROR(("Cannot open file %s for writing: %s", filename, strerror(errno))); return -1; @@ -90,8 +95,13 @@ int silc_file_writefile_mode(const char *filename, const char *buffer, SilcUInt32 len, int mode) { int fd; + int flags = O_CREAT | O_WRONLY | O_TRUNC; + +#if defined(O_BINARY) + flags |= O_BINARY; +#endif /* O_BINARY */ - if ((fd = creat(filename, mode)) == -1) { + if ((fd = open(filename, flags, mode)) == -1) { SILC_LOG_ERROR(("Cannot open file %s for writing: %s", filename, strerror(errno))); return -1;