summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2001-05-09 23:45:52 +0000
committerJose Antonio Ortega Ruiz <jao@gnu.org>2001-05-09 23:45:52 +0000
commit798bd5f5ef4fab21b774833c0eed1de744f125b4 (patch)
tree1b422468564649d670127ba8b8caa7e575cdae8a
parentc74b04dd0d007cca8db58659e8a20555a88f1023 (diff)
downloadmdk-798bd5f5ef4fab21b774833c0eed1de744f125b4.tar.gz
mdk-798bd5f5ef4fab21b774833c0eed1de744f125b4.tar.bz2
read/write files not truncated if they already exist
-rw-r--r--mixlib/mix_file.c10
-rw-r--r--mixlib/xmix_io.c2
2 files changed, 10 insertions, 2 deletions
diff --git a/mixlib/mix_file.c b/mixlib/mix_file.c
index 6ee88ec..ac623f6 100644
--- a/mixlib/mix_file.c
+++ b/mixlib/mix_file.c
@@ -48,9 +48,17 @@ open_file_(const gchar *name, mix_fmode_t mode)
{
mix_file_t *result;
FILE *file;
+ const gchar *fmode = fmode_to_type_ (mode);
+
+ /* if the read/write file already exists, open in r+ mode */
+ if (mode == mix_io_RDWRT && (file = fopen (name, "r")))
+ {
+ fmode = "r+";
+ fclose (file);
+ }
result = g_new(mix_file_t, 1);
- file = fopen(name, fmode_to_type_(mode));
+ file = fopen(name, fmode);
if ( file == NULL ) {
g_free (result);
return NULL;
diff --git a/mixlib/xmix_io.c b/mixlib/xmix_io.c
index 075b185..b9881c0 100644
--- a/mixlib/xmix_io.c
+++ b/mixlib/xmix_io.c
@@ -25,7 +25,7 @@
#include <fcntl.h>
#include "xmix_io.h"
-const char *io_OPENTYPE_[5] = { "r", "w", "r+", "a", "a+" };
+const char *io_OPENTYPE_[5] = { "r", "w", "w+", "a", "a+" };
/* initialise a mix_iochannel from a file descriptor */