Commit 7f12a67b authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

use sys_close and sys_open in most places

parent 955cc2c4
Pipeline #1720 canceled with stage
in 6 minutes and 3 seconds
......@@ -9,7 +9,7 @@ These operations are not to be done in "real time" as they may have to wait
for disk accesses (even the write routine.) Finally, the realtime objects
readsf~ and writesf~ are defined which confine disk operations to a separate
thread so that they can be used in real time. The readsf~ and writesf~
objects use Posix-like threads. */
objects use Posix-like threads. */
#include "config.h"
......@@ -38,10 +38,10 @@ objects use Posix-like threads. */
#ifdef _LARGEFILE64_SOURCE
# define open open64
# define lseek lseek64
#define off_t __off64_t
# define off_t __off64_t
#endif
#ifdef MSW
#define off_t long
# define off_t long
#endif
/***************** soundfile header structures ************************/
......@@ -869,7 +869,7 @@ static int create_soundfile(t_canvas *canvas, const char *filename,
if (write(fd, headerbuf, headersize) < headersize)
{
close (fd);
sys_close (fd);
return (-1);
}
return (fd);
......@@ -1382,7 +1382,7 @@ usage:
post("-raw <headerbytes> <channels> <bytespersamp> <endian (b, l, or n)>.");
done:
if (fd >= 0)
close (fd);
sys_close(fd);
outlet_float(x->x_obj.ob_outlet, (t_float)itemsread);
}
......@@ -1487,7 +1487,7 @@ long soundfiler_dowrite(void *obj, t_canvas *canvas,
{
soundfile_finishwrite(obj, filesym->s_name, fd,
filetype, nframes, itemswritten, nchannels * bytespersamp, swap);
close (fd);
sys_close(fd);
}
return ((float)itemswritten);
usage:
......@@ -1497,7 +1497,7 @@ usage:
post("(defaults to a 16-bit wave file).");
fail:
if (fd >= 0)
close (fd);
sys_close(fd);
return (0);
}
......@@ -1680,7 +1680,7 @@ static void *readsf_child_main(void *zz)
{
fd = x->x_fd;
pthread_mutex_unlock(&x->x_mutex);
close (fd);
sys_close(fd);
pthread_mutex_lock(&x->x_mutex);
x->x_fd = -1;
if (x->x_requestcode != REQUEST_BUSY)
......@@ -1863,7 +1863,7 @@ static void *readsf_child_main(void *zz)
{
fd = x->x_fd;
pthread_mutex_unlock(&x->x_mutex);
close (fd);
sys_close(fd);
pthread_mutex_lock(&x->x_mutex);
x->x_fd = -1;
}
......@@ -1876,7 +1876,7 @@ static void *readsf_child_main(void *zz)
{
fd = x->x_fd;
pthread_mutex_unlock(&x->x_mutex);
close (fd);
sys_close(fd);
pthread_mutex_lock(&x->x_mutex);
x->x_fd = -1;
}
......@@ -1890,7 +1890,7 @@ static void *readsf_child_main(void *zz)
{
fd = x->x_fd;
pthread_mutex_unlock(&x->x_mutex);
close (fd);
sys_close(fd);
pthread_mutex_lock(&x->x_mutex);
x->x_fd = -1;
}
......@@ -2246,7 +2246,7 @@ static void *writesf_child_main(void *zz)
soundfile_finishwrite(x, filename, fd,
filetype, 0x7fffffff, itemswritten,
bytesperframe, swap);
close (fd);
sys_close(fd);
pthread_mutex_lock(&x->x_mutex);
x->x_fd = -1;
......@@ -2387,7 +2387,7 @@ static void *writesf_child_main(void *zz)
soundfile_finishwrite(x, filename, fd,
filetype, 0x7fffffff, itemswritten,
bytesperframe, swap);
close (fd);
sys_close(fd);
pthread_mutex_lock(&x->x_mutex);
x->x_fd = -1;
......
......@@ -964,13 +964,13 @@ int binbuf_read(t_binbuf *b, char *filename, char *dirname, int crflag)
int readret;
char *buf;
char namebuf[MAXPDSTRING];
if (*dirname)
snprintf(namebuf, MAXPDSTRING-1, "%s/%s", dirname, filename);
else
snprintf(namebuf, MAXPDSTRING-1, "%s", filename);
namebuf[MAXPDSTRING-1] = 0;
if ((fd = sys_open(namebuf, 0)) < 0)
{
//fprintf(stderr, "open: ");
......@@ -982,14 +982,14 @@ int binbuf_read(t_binbuf *b, char *filename, char *dirname, int crflag)
{
//fprintf(stderr, "lseek: ");
perror(namebuf);
close(fd);
sys_close(fd);
return(1);
}
if ((readret = read(fd, buf, length)) < length)
{
//fprintf(stderr, "read (%d %ld) -> %d\n", fd, length, readret);
perror(namebuf);
close(fd);
sys_close(fd);
t_freebytes(buf, length);
return(1);
}
......@@ -1008,7 +1008,7 @@ int binbuf_read(t_binbuf *b, char *filename, char *dirname, int crflag)
#endif
t_freebytes(buf, length);
close(fd);
sys_close(fd);
return (0);
}
......@@ -1024,7 +1024,7 @@ int binbuf_read_via_canvas(t_binbuf *b, char *filename, t_canvas *canvas,
error("%s: can't open", filename);
return (1);
}
else close (filedesc);
else sys_close(filedesc);
if (binbuf_read(b, bufptr, buf, crflag))
return (1);
else return (0);
......@@ -1042,7 +1042,7 @@ int binbuf_read_via_path(t_binbuf *b, char *filename, char *dirname,
error("%s: can't open", filename);
return (1);
}
else close (filedesc);
else sys_close(filedesc);
if (binbuf_read(b, bufptr, buf, crflag))
return (1);
else return (0);
......
......@@ -72,7 +72,7 @@ static void sys_initloadpreferences( void)
else
return;
filenamebuf[FILENAME_MAX-1] = 0;
if ((fd = open(filenamebuf, 0)) < 0)
if ((fd = sys_open(filenamebuf, 0)) < 0)
{
if (sys_verbose)
perror(filenamebuf);
......@@ -83,14 +83,14 @@ static void sys_initloadpreferences( void)
{
if (sys_verbose)
perror(filenamebuf);
close(fd);
sys_close(fd);
return;
}
lseek(fd, 0, 0);
if (!(sys_prefbuf = malloc(length + 2)))
{
error("couldn't allocate memory for preferences buffer");
close(fd);
sys_close(fd);
return;
}
sys_prefbuf[0] = '\n';
......@@ -98,11 +98,11 @@ static void sys_initloadpreferences( void)
{
perror(filenamebuf);
sys_prefbuf[0] = 0;
close(fd);
sys_close(fd);
return;
}
sys_prefbuf[length+1] = 0;
close(fd);
sys_close(fd);
if (sys_verbose)
post("success reading preferences from: %s", filenamebuf);
}
......@@ -156,7 +156,7 @@ static void sys_initsavepreferences( void)
}
snprintf(filenamebuf, FILENAME_MAX, "%s/" USER_CONFIG_DIR "/user.settings", homedir);
filenamebuf[FILENAME_MAX-1] = 0;
if ((sys_prefsavefp = fopen(filenamebuf, "w")) == NULL)
if ((sys_prefsavefp = sys_fopen(filenamebuf, "w")) == NULL)
{
//snprintf(errbuf, FILENAME_MAX, "%s: %s",filenamebuf, strerror(errno));
pd_error(0, "%s: %s",filenamebuf, strerror(errno));
......@@ -883,7 +883,7 @@ void sys_save_recent_files(void)
}
snprintf(filenamebuf, FILENAME_MAX, "%s/" USER_CONFIG_DIR "/recent_files", homedir);
filenamebuf[FILENAME_MAX-1] = 0;
if ((fp = fopen(filenamebuf, "w")) == NULL) {
if ((fp = sys_fopen(filenamebuf, "w")) == NULL) {
pd_error(0, "%s: %s",filenamebuf, strerror(errno));
return;
}
......@@ -914,7 +914,7 @@ void sys_load_recent_files(void)
if (!homedir) return;
snprintf(filenamebuf, FILENAME_MAX, "%s/" USER_CONFIG_DIR "/recent_files", homedir);
filenamebuf[FILENAME_MAX-1] = 0;
if ((fp = fopen(filenamebuf, "r")) == NULL) return;
if ((fp = sys_fopen(filenamebuf, "r")) == NULL) return;
for (sys_n_recent_files = 0; sys_n_recent_files < MAX_RECENT_FILES &&
fgets(filenamebuf, FILENAME_MAX, fp); ) {
char *s;
......
......@@ -219,7 +219,7 @@ static int sys_do_load_lib(t_canvas *canvas, const char *objectname,
#endif
return (0);
gotone:
close(fd);
sys_close(fd);
class_set_extern_dir(gensym(dirbuf));
/* rebuild the absolute pathname */
......@@ -444,7 +444,6 @@ int sys_run_scheduler(const char *externalschedlibname,
}
}
/* abstraction loading */
void canvas_popabstraction(t_canvas *x);
int pd_setloadingabstraction(t_symbol *sym);
......@@ -474,7 +473,7 @@ static t_pd *do_create_abstraction(t_symbol*s, int argc, t_atom *argv)
(fd = canvas_open(canvas, classslashclass, ".pd",
dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
{
close(fd);
sys_close(fd);
canvas_setargs(argc, argv);
binbuf_evalfile(gensym(nameptr), gensym(dirbuf));
......@@ -510,11 +509,11 @@ static int sys_do_load_abs(t_canvas *canvas, const char *objectname,
(fd = sys_trytoopenone(path, classslashclass, ".pd",
dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0)
{
t_class*c=0;
close(fd);
t_class *c = 0;
sys_close(fd);
/* found an abstraction, now register it as a new pseudo-class */
class_set_extern_dir(gensym(dirbuf));
if((c=class_new(gensym(objectname),
if ((c=class_new(gensym(objectname),
(t_newmethod)do_create_abstraction, 0,
0, 0, A_GIMME, 0)))
{
......
......@@ -172,7 +172,7 @@ static void openit(const char *dirname, const char *filename)
FILENAME_MAX, 0);
if (fd >= 0)
{
close (fd);
sys_close(fd);
glob_evalfile(0, gensym(nameptr), gensym(dirbuf));
gui_vmess("gui_process_open_arg", "s", filename);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment