diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-05-09 23:45:52 +0000 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-05-09 23:45:52 +0000 |
commit | 315f949aeef1935bcdde67a9e19ed3397ffda851 (patch) | |
tree | a176606ba549b5e590e9f6db3954ad6ab0bb0c9f | |
parent | b557cadb2c884e054560408dcc866110208ba1a2 (diff) | |
download | mdk-315f949aeef1935bcdde67a9e19ed3397ffda851.tar.gz mdk-315f949aeef1935bcdde67a9e19ed3397ffda851.tar.bz2 |
read/write files not truncated if they already exist
-rw-r--r-- | mixlib/mix_file.c | 10 | ||||
-rw-r--r-- | mixlib/xmix_io.c | 2 |
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 */ |