From 4589a8c0ad67e9b1178b06027f877bcfbbc3861b Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Wed, 20 Feb 2013 21:02:18 +0000 Subject: fopen and fclose -> sys_fopen and sys_fclose for recent pd svn path=/trunk/externals/mrpeach/; revision=17049 --- str/str.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/str/str.c b/str/str.c index c5c564f..0e4d7e9 100644 --- a/str/str.c +++ b/str/str.c @@ -6,6 +6,13 @@ #include #include "m_pd.h" +/* support older Pd versions without sys_open(), sys_fopen(), sys_fclose() */ +#if PD_MAJOR_VERSION == 0 && PD_MINOR_VERSION < 44 +#define sys_open open +#define sys_fopen fopen +#define sys_fclose fclose +#endif + #ifndef PD_BLOBS /* PD_BLOBS is not defined in m_pd.h: No PD blob support: Make a dummy str object */ typedef struct _str { @@ -378,7 +385,7 @@ static void str_fread(t_str *x, t_symbol *s, int argc, t_atom *argv) return; } errno = 0; - fp = fopen((char *)x->x_buf.s_data, "rb"); + fp = sys_fopen((char *)x->x_buf.s_data, "rb"); if(NULL == fp) { post ("str file_read: error opening file \"%s\": %d", x->x_buf.s_data, errno); @@ -396,7 +403,7 @@ static void str_fread(t_str *x, t_symbol *s, int argc, t_atom *argv) x->x_string_in1_end = limit; post ("str file_read: read %lu bytes", limit); } - fclose(fp); + sys_fclose(fp); return; } @@ -422,7 +429,7 @@ static void str_fwrite(t_str *x, t_symbol *s, int argc, t_atom *argv) return; } errno = 0; - fp = fopen((char *)x->x_buf.s_data, "wb"); + fp = sys_fopen((char *)x->x_buf.s_data, "wb"); if(NULL == fp) { post ("str file_write: error opening file \"%s\": %d", x->x_buf.s_data, errno); @@ -434,7 +441,7 @@ static void str_fwrite(t_str *x, t_symbol *s, int argc, t_atom *argv) if (0 != (err = ferror(fp))) post ("str file_write: error writing file \"%s\": %d", x->x_buf.s_data, errno); else post ("str file_write: wrote %lu bytes to \"%s\"", limit, x->x_buf.s_data); - fclose(fp); + sys_fclose(fp); return; } -- cgit v1.2.1