Revision: 9686 http://pure-data.svn.sourceforge.net/pure-data/?rev=9686&view=rev Author: zmoelnig Date: 2008-04-09 11:43:23 -0700 (Wed, 09 Apr 2008)
Log Message: ----------- changed read() to fread()
Modified Paths: -------------- trunk/externals/zexy/src/msgfile.c
Modified: trunk/externals/zexy/src/msgfile.c =================================================================== --- trunk/externals/zexy/src/msgfile.c 2008-04-08 22:01:33 UTC (rev 9685) +++ trunk/externals/zexy/src/msgfile.c 2008-04-09 18:43:23 UTC (rev 9686) @@ -26,12 +26,6 @@ #include <fcntl.h> #include <string.h>
-#ifdef __WIN32__ -# include <io.h> -#else -# include <unistd.h> -#endif - /* ****************************************************************************** */ /* msgfile : save and load messages... */
@@ -542,7 +536,8 @@ { int rmode = 0;
- int fd; + int fd=0; + FILE*fil=NULL; long readlength, length, pos; char filnam[MAXPDSTRING], namebuf[MAXPDSTRING]; char buf[MAXPDSTRING], *bufptr, *readbuf; @@ -563,11 +558,31 @@ filename->s_name, "", buf, &bufptr, MAXPDSTRING, 0)) < 0) {
if((fd=open(filename->s_name, rmode)) < 0) { - pd_error(x, "%s: can't open in %s", filename->s_name, dirname); + pd_error(x, "can't open in %s/%s", dirname, filename->s_name); return; + } else { + sprintf(filnam, "%s", filename->s_name); } + } else { + close(fd); + sprintf(filnam, "%s/%s", buf, bufptr); }
+ fil=fopen(filnam, "r"); + fseek(fil, 0, SEEK_END); + if(fil==NULL) { + pd_error(x, "could not open '%s'", filnam); + return; + } + length=ftell(fil); + fseek(fil, 0, SEEK_SET); + + if (!(readbuf = t_getbytes(length))) { + pd_error(x, "msgfile_read: could not reserve %d bytes to read into", length); + close(fd); + return; + } + if (gensym("cr")==format) { mode = CR_MODE; } else if (gensym("csv")==format) { @@ -592,28 +607,17 @@ break; }
- if ((length = lseek(fd, 0, SEEK_END)) < 0 || lseek(fd, 0,SEEK_SET) < 0) { - pd_error(x, "msgfile_read: unable to lseek %s", filnam); - close(fd); - return; - }
- if (!(readbuf = t_getbytes(length))) { - pd_error(x, "msgfile_read: could not reserve %d bytes to read into", length); - close(fd); - return; - } - /* read */ - if ((readlength = read(fd, readbuf, length)) < length) { - pd_error(x, "msgfile_read: unable to read %s", filnam); - close(fd); + if ((readlength = fread(readbuf, sizeof(char), length, fil)) < length) { + pd_error(x, "msgfile_read: unable to read %s: %d of %d", filnam, readlength, length); + fclose(fil); t_freebytes(readbuf, length); return; }
/* close */ - close(fd); + fclose(fil);
/* convert separators and eols to what pd expects in a binbuf*/ bufptr=readbuf;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.