diff --git a/externals/creb/modules/bmatrix~.c b/externals/creb/modules/bmatrix~.c
index 05c726889c6677a786e9053c075227bcb25d65c4..90676b448407c79f3fdd98d185fcd459602225a7 100644
--- a/externals/creb/modules/bmatrix~.c
+++ b/externals/creb/modules/bmatrix~.c
@@ -49,7 +49,7 @@ static void matrix_load(t_matrix *x, t_symbol *s)
   if(s && s->s_name)
     {
       post("matrix: loading %s",s->s_name);
-      if(matrix = fopen(s->s_name, "r"))
+      if(matrix = sys_fopen(s->s_name, "r"))
 	{
 	  int n = x->x_ctl.c_order;
 	  fread(x->x_ctl.c_A, sizeof(t_float), n*n, matrix);
diff --git a/externals/cxc/ascwave.c b/externals/cxc/ascwave.c
index 22f85b8522136bec163a67e3064222d169d17710..4c9978a776fd67031b832e72958d967d80e08466 100644
--- a/externals/cxc/ascwave.c
+++ b/externals/cxc/ascwave.c
@@ -49,7 +49,7 @@ static void ascwave_open(t_ascwave *x, t_symbol *filename)
      post("ascwave: open");
      x->filename = filename;
      post("ascwave: filename = %s",x->filename->s_name);
-     if ((x->x_file = fopen(x->filename->s_name,"w")) < 0)
+     if ((x->x_file = sys_fopen(x->filename->s_name,"w")) < 0)
      {
 	  error("can't create %s",filename->s_name);
 	  return;
diff --git a/externals/earplug~/earplug~.c b/externals/earplug~/earplug~.c
index c53d3207a7295d1a7c6e8fff669197fc28ebdde9..a72d6dd5c333157bd3545c7400a50eb477567170 100644
--- a/externals/earplug~/earplug~.c
+++ b/externals/earplug~/earplug~.c
@@ -200,7 +200,7 @@ static void *earplug_new(t_floatarg azimArg, t_floatarg elevArg)
 				fscanf(fp, "%f %f ", &earplug_impulses[i][0][j], &earplug_impulses[i][1][j]);
             }
         }
-        fclose(fp) ;
+        sys_fclose(fp) ;
     }
     x->impulses = earplug_impulses;
     
diff --git a/externals/ext13/sfread.c b/externals/ext13/sfread.c
index 9d990a47b843d8135bc6e0795a72ae83c37d9ee3..caa467297b2d2da2dce35eacc3b844b13ffa6bd1 100644
--- a/externals/ext13/sfread.c
+++ b/externals/ext13/sfread.c
@@ -52,9 +52,9 @@ void sfread_open(t_sfread *x,t_symbol *filename)
      /* close the old file */
 
      if (x->x_mapaddr) munmap(x->x_mapaddr,x->x_size);
-     if (x->x_fd >= 0) close(x->x_fd);
+     if (x->x_fd >= 0) sys_close(x->x_fd);
 
-     if ((x->x_fd = open(fname,O_RDONLY)) < 0)
+     if ((x->x_fd = sys_open(fname,O_RDONLY)) < 0)
      {
 	  error("can't open %s",fname);
 	  return;
diff --git a/externals/ext13/sfwrite13~.c b/externals/ext13/sfwrite13~.c
index ecf4532ddb8ce1f232b9c29b0dd3d45bc41c2879..f35916c3715cd9eaf9a8e95e06350e86d4e1d62c 100644
--- a/externals/ext13/sfwrite13~.c
+++ b/externals/ext13/sfwrite13~.c
@@ -140,7 +140,7 @@ static void sfwrite13_close(t_sfwrite13 *x)
 	  sfwrite13_wave_setup(x,&w);
 	  lseek(x->x_file,0,SEEK_SET);
 	  write(x->x_file,&w,sizeof(w));
-	  close(x->x_file);
+	  sys_close(x->x_file);
      }
      x->x_file = -1;
 }
@@ -164,7 +164,7 @@ static void sfwrite13_open(t_sfwrite13 *x,t_symbol *filename)
 
      sfwrite13_close(x);
 
-     if ((x->x_file = open(fname,OPENPARAMS,0664)) < 0)
+     if ((x->x_file = sys_open(fname,OPENPARAMS,0664)) < 0)
      {
 	  error("can't create %s",fname);
 	  return;
diff --git a/externals/ggee/gui/.image.c.swp b/externals/ggee/gui/.image.c.swp
deleted file mode 100644
index a7e8f8fc4ce7668ff2b1f77e2e96e7a06db183d3..0000000000000000000000000000000000000000
Binary files a/externals/ggee/gui/.image.c.swp and /dev/null differ
diff --git a/externals/ggee/gui/image.c b/externals/ggee/gui/image.c
index 67795a1338229bc096b6f492603535c0206148b6..ae501c4323741cd9099f041a9352866455f14307 100644
--- a/externals/ggee/gui/image.c
+++ b/externals/ggee/gui/image.c
@@ -45,9 +45,9 @@ t_symbol *image_trytoopen(t_image* x)
     canvas_makefilename(glist_getcanvas(x->x_glist), x->x_fname->s_name,
         fname, FILENAME_MAX);
     // try to open the file
-    if (file = fopen(fname, "r"))
+    if (file = sys_fopen(fname, "r"))
     {
-        fclose(file);
+        sys_fclose(file);
         return gensym(fname);
     }
     else
diff --git a/externals/ggee/gui/state.c b/externals/ggee/gui/state.c
index 063b15f103ac51e30857b39315854a58072716ba..dd6cad366f59ff9d85c19578f9945df866598af6 100644
--- a/externals/ggee/gui/state.c
+++ b/externals/ggee/gui/state.c
@@ -90,7 +90,7 @@ void state_dosave(t_state *x)
      else
 	  sprintf(name,"%s%s.%d",dirstr,x->x_name->s_name,x->x_slot);
 
-     fp = fopen(name,"w");
+     fp = sys_fopen(name,"w");
      if (!fp) {
 	  post("state: unable to open %s",name);
 	  return;
@@ -151,7 +151,7 @@ void state_dosave(t_state *x)
      } while ((a = (t_text*)((t_gobj*)a)->g_next));
      post("state saved to: %s",name);
 
-     fclose(fp);
+     sys_fclose(fp);
 
 }
 
diff --git a/externals/ggee/other/vbap.c b/externals/ggee/other/vbap.c
index 57dae7b8e1fd3b1f23ad7f2a3877d9deaf36bf6f..cf3b4d90e5e3d28e09161d4b70336a7083ef56d3 100644
--- a/externals/ggee/other/vbap.c
+++ b/externals/ggee/other/vbap.c
@@ -122,7 +122,7 @@ static void *vbap_new(t_symbol* s)
      canvas_makefilename(canvas_getcurrent(),s->s_name,
                          fname,MAXPDSTRING);
 
-     if((fp=fopen(fname,"r"))==NULL){
+     if((fp=sys_fopen(fname,"r"))==NULL){
 	  post("vbap: Could not open loudspeaker data file %s\n",fname);
 	  x->opened = 0;
      }
@@ -130,7 +130,7 @@ static void *vbap_new(t_symbol* s)
 	  if (!read_ls_conf(x,fp))
 	       return NULL;
 	  x->opened = 1;
-	  fclose(fp);
+	  sys_fclose(fp);
      }
 
      x->lasttrip[0] = 0;
diff --git a/externals/ggee/signal/sfwrite~.c b/externals/ggee/signal/sfwrite~.c
index 1209572c5b344a6e878cbf7790c4c815c2fb0734..706094c4bb9205883eda2f8ba58ca7e5235f88ca 100644
--- a/externals/ggee/signal/sfwrite~.c
+++ b/externals/ggee/signal/sfwrite~.c
@@ -99,7 +99,7 @@ static void sfwrite_close(t_sfwrite *x)
 	  sfwrite_wave_setup(x,&w);
 	  lseek(x->x_file,0,SEEK_SET);
 	  write(x->x_file,&w,sizeof(w));
-	  close(x->x_file);
+	  sys_close(x->x_file);
      }
      x->x_file = -1;
 }
@@ -123,7 +123,7 @@ static void sfwrite_open(t_sfwrite *x,t_symbol *filename)
 
      sfwrite_close(x);
 
-     if ((x->x_file = open(fname,OPENPARAMS,0664)) < 0)
+     if ((x->x_file = sys_open(fname,OPENPARAMS,0664)) < 0)
      {
 	  error("can't create %s",fname);
 	  return;
diff --git a/externals/grh/adaptive/src/adaptive.c b/externals/grh/adaptive/src/adaptive.c
index 5c3b6515fe769e71de21a3c676ea3f92c6117eaa..02aae8b749e2653f11832366ee50e265a4a4d217 100644
--- a/externals/grh/adaptive/src/adaptive.c
+++ b/externals/grh/adaptive/src/adaptive.c
@@ -79,7 +79,7 @@ void adaptation_write(const char *filename, t_int N, t_float mu, t_float *c)
   int i;
 
   // open file
-  f = fopen(filename, "w");
+  f = sys_fopen(filename, "w");
   if(!f)
   {
     post("adaptive, save: error open file");
@@ -96,7 +96,7 @@ void adaptation_write(const char *filename, t_int N, t_float mu, t_float *c)
     fprintf(f, "%.30f\n", c[i]);
 
   // close file
-  if (f) fclose(f);
+  if (f) sys_fclose(f);
   post("adaptive, save: coefficients written to file");
 }
 
@@ -107,7 +107,7 @@ void adaptation_read(const char *filename, t_int *N, t_float *mu,
   int i, n=0;
 
   // open file
-  f = fopen(filename, "r");
+  f = sys_fopen(filename, "r");
   if(!f)
   {
     post("adaptive, open: error open file");
diff --git a/externals/iem/iemgui/src/iem_image.c b/externals/iem/iemgui/src/iem_image.c
index 52f8c6115caf95bb94b7389d30f3c281af3355b7..faec94671f2fa944065ae9d05c06bf087a3c9f8e 100644
--- a/externals/iem/iemgui/src/iem_image.c
+++ b/externals/iem/iemgui/src/iem_image.c
@@ -57,11 +57,11 @@ static t_symbol *iem_image_calc_size(t_iem_image *x)
   else
   {
     if(fd >= 0)
-      close(fd);
+      sys_close(fd);
     strcpy(namebuf, dirbuf);
     strcat(namebuf, "/");
     strcat(namebuf, namebufptr);
-    fh = fopen(namebuf, "r");
+    fh = sys_fopen(namebuf, "r");
     if(fh == NULL)
     {
       post("iem_image-ERROR: cannot open %s second time", namebuf);
@@ -76,7 +76,7 @@ static t_symbol *iem_image_calc_size(t_iem_image *x)
         x->x_gifsym = (t_symbol *)0;
         return((t_symbol *)0);
         };
-      fclose(fh);
+      sys_fclose(fh);
       c = (char *)buf;
       if((c[0] != 'G')||(c[1] != 'I')||(c[2] != 'F'))
       {
diff --git a/externals/iemlib/iem_mp3/src/mp3play~.c b/externals/iemlib/iem_mp3/src/mp3play~.c
index d4c342a442ee338513b978da06b562e04864337d..bab4089c09b59292bb58d23110e366f27ca83c0f 100644
--- a/externals/iemlib/iem_mp3/src/mp3play~.c
+++ b/externals/iemlib/iem_mp3/src/mp3play~.c
@@ -3174,7 +3174,7 @@ static void *mp3play_tilde_new(void)
 static void mp3play_tilde_cleanup(t_mp3play_tilde *x)
 {
     x->file_is_open = 0;
-    fclose(x->fh);
+    sys_fclose(x->fh);
     x->play_state = 0;
     x->mp3_out_index = 0;
     x->mp_is_init = 0;
@@ -3404,7 +3404,7 @@ static void mp3play_tilde_do_open(t_mp3play_tilde *x, char *str, int calc_it)
         strcat(completefilename, str);
       }
 
-  if((x->fh = fopen(completefilename, "rb")) == NULL)
+  if((x->fh = sys_fopen(completefilename, "rb")) == NULL)
   {
       post("mp3play-ERROR: cannot open %s", completefilename);
   }
@@ -3520,13 +3520,13 @@ static void mp3play_tilde_do_open(t_mp3play_tilde *x, char *str, int calc_it)
     {
         x->file_is_open = 0;
         x->mp3_out_index = 0;
-        fclose(x->fh);
+        sys_fclose(x->fh);
     }
       }
       else
       {
     x->file_is_open = 0;
-    fclose(x->fh);
+    sys_fclose(x->fh);
       }
   }
   x->play_state = 2;
diff --git a/externals/iemlib/iemlib1/src/soundfile_info.c b/externals/iemlib/iemlib1/src/soundfile_info.c
index f018370a69b53879df9fd6347b6509ed754b1e62..aa49cf5a4c1d40e1ffb5c3128bbb9bd35fd6f809 100644
--- a/externals/iemlib/iemlib1/src/soundfile_info.c
+++ b/externals/iemlib/iemlib1/src/soundfile_info.c
@@ -99,7 +99,7 @@ static void soundfile_info_overwrite_sr(t_soundfile_info *x, t_symbol *filename,
     strcat(completefilename, filename->s_name);
   }
   
-  fh = fopen(completefilename,"r+b");
+  fh = sys_fopen(completefilename,"r+b");
   if(!fh)
   {
     post("soundfile_info_read: cannot open %s !!\n", completefilename);
@@ -187,7 +187,7 @@ static void soundfile_info_overwrite_sr(t_soundfile_info *x, t_symbol *filename,
       
       fseek(fh,0,SEEK_SET);
       read_chars = (int)fwrite (x->x_begmem, sizeof(char), n4, fh);
-      fclose(fh);
+      sys_fclose(fh);
       post("written");
       
       sr = (int)ul_sr;
@@ -268,7 +268,7 @@ static void soundfile_info_read(t_soundfile_info *x, t_symbol *filename)
     strcat(completefilename, filename->s_name);
   }
   
-  fh = fopen(completefilename,"rb");
+  fh = sys_fopen(completefilename,"rb");
   if(!fh)
   {
     post("soundfile_info_read: cannot open %s !!\n", completefilename);
@@ -282,7 +282,7 @@ static void soundfile_info_read(t_soundfile_info *x, t_symbol *filename)
     filesize = ftell(fh);
     fseek(fh,0,SEEK_SET);
     read_chars = (int)fread(x->x_begmem, sizeof(char), n4, fh) / 2;
-    fclose(fh);
+    sys_fclose(fh);
     //    post("read chars = %d", read_chars);
     cvec = (char *)x->x_begmem;
     if(read_chars > 4)
diff --git a/externals/iemlib/iemlib2/src/iem_pbank_csv.c b/externals/iemlib/iemlib2/src/iem_pbank_csv.c
index cb919a9325c53add093008aa0ef9d60ecd096303..d24b055cdf3cfb80b295a03baed7c0fe451265e3 100644
--- a/externals/iemlib/iemlib2/src/iem_pbank_csv.c
+++ b/externals/iemlib/iemlib2/src/iem_pbank_csv.c
@@ -88,7 +88,7 @@ static void iem_pbank_csv_write(t_iem_pbank_csv *x, t_symbol *filename, t_symbol
     strcat(completefilename, filename->s_name);
   }
   
-  fh = fopen(completefilename,"wb");
+  fh = sys_fopen(completefilename,"wb");
   if(!fh)
   {
     post("iem_pbank_csv_write: cannot create %s !!\n", completefilename);
@@ -172,7 +172,7 @@ static void iem_pbank_csv_write(t_iem_pbank_csv *x, t_symbol *filename, t_symbol
         fprintf(fh, "%s%s", ap->a_w.w_symbol->s_name, eol+eol_offset);
       ap++;
     }
-    fclose(fh);
+    sys_fclose(fh);
     post("iem_pbank_csv: wrote %d parameters x %d lines to file:\n%s\nwith following format:\n%s\n", nrp, nrl, completefilename, formattext);
   }
 }
@@ -407,7 +407,7 @@ static void iem_pbank_csv_read(t_iem_pbank_csv *x, t_symbol *filename, t_symbol
        strcat(completefilename, filename->s_name);
      }
      
-     fh = fopen(completefilename,"rb");
+     fh = sys_fopen(completefilename,"rb");
      if(!fh)
      {
        post("iem_pbank_csv_read: cannot open %s !!\n", completefilename);
@@ -481,7 +481,7 @@ static void iem_pbank_csv_read(t_iem_pbank_csv *x, t_symbol *filename, t_symbol
        txbuf2 = (char *)getbytes((2 * txalloc + 256) * sizeof(char));
        if(fread(txbuf1, sizeof(char), txalloc, fh) < sizeof(char)*txalloc)
          post("pbank.csv:435: warning read error (not specified)");
-       fclose(fh);
+       sys_fclose(fh);
        
 	// 1.)  allow only readable ASCII (0x09, 0x0a, 0x0d, 0x20...0x7e = 
   //      = TAB, LF, CR, ' ' ... '~' = 
diff --git a/externals/lyonpotpourri/sigseq~.c b/externals/lyonpotpourri/sigseq~.c
index 7282b65fb37b5c7819b9d7c19386751f55ae39b8..8cffb3f26f153b5ab815978ffab743dc280d70b6 100755
--- a/externals/lyonpotpourri/sigseq~.c
+++ b/externals/lyonpotpourri/sigseq~.c
@@ -141,7 +141,7 @@ void sigseq_readfile(t_sigseq *x, t_symbol *filename)
     FILE *fp;
     float data;
     post("requested path: %s", filename->s_name);
-    fp = fopen(filename->s_name, "r");
+    fp = sys_fopen(filename->s_name, "r");
     if( fp == NULL ){
         post("could not open file!");
         return;
@@ -149,7 +149,7 @@ void sigseq_readfile(t_sigseq *x, t_symbol *filename)
     while( fscanf(fp, "%f", &data) != EOF ){
         post("%f",data);
     }
-    fclose(fp);
+    sys_fclose(fp);
 }
 
 void sigseq_mute(t_sigseq *x, t_symbol *msg, short argc, t_atom *argv)
diff --git a/externals/moonlib/image.c b/externals/moonlib/image.c
index f8a1fe2e096c85945f19d3b3319726fa68938901..0146cdf9b9352914a3f3ef1c6fe49380c6bd3993 100644
--- a/externals/moonlib/image.c
+++ b/externals/moonlib/image.c
@@ -43,7 +43,7 @@ static const char *image_get_filename(t_image *x, char *file)
            retrieve the full path... */
         fullpath = dirresult;
         fullpath[strlen(fullpath)] = '/';
-        close(fd);
+        sys_close(fd);
         return fullpath;
     }
     else return 0;
diff --git a/externals/moonlib/readsfv~.c b/externals/moonlib/readsfv~.c
index 1c2cb5291c75d3d7a1f2da90a6b52078383c27f7..ec2c2315662535c1083a514a16c19921365f9b80 100644
--- a/externals/moonlib/readsfv~.c
+++ b/externals/moonlib/readsfv~.c
@@ -523,12 +523,12 @@ static int create_soundfile2(t_canvas *canvas, const char *filename,
 
     canvas_makefilename(canvas, filenamebuf, buf2, MAXPDSTRING);
     sys_bashfilename(buf2, buf2);
-    if ((fd = open(buf2, BINCREATE, 0666)) < 0)
+    if ((fd = sys_open(buf2, BINCREATE, 0666)) < 0)
         return (-1);
 
     if (write(fd, headerbuf, headersize) < headersize)
     {
-        close (fd);
+        sys_close (fd);
         return (-1);
     }
     return (fd);
@@ -914,7 +914,7 @@ static void soundfiler2_read(t_soundfiler2 *x, t_symbol *s,
     /* do all graphics updates */
     for (i = 0; i < argc; i++)
         garray_redraw(garrays[i]);
-    fclose(fp);
+    sys_fclose(fp);
     fd = -1;
     goto done;
 usage:
@@ -923,7 +923,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, (float)itemsread);
 }
 
@@ -1029,7 +1029,7 @@ static long soundfiler2_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:
@@ -1039,7 +1039,7 @@ usage:
     post("(defaults to a 16-bit wave file).");
 fail:
     if (fd >= 0)
-        close (fd);
+        sys_close (fd);
     return (0);
 }
 
@@ -1230,7 +1230,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)
@@ -1383,7 +1383,7 @@ lost:
             {
                 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;
             }
@@ -1396,7 +1396,7 @@ lost:
             {
                 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;
             }
@@ -1410,7 +1410,7 @@ lost:
             {
                 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;
             }
diff --git a/externals/moonlib/sfread2~.c b/externals/moonlib/sfread2~.c
index e5e2a6fb9df352e99c4c28856ccfb9b43af9226c..8e7329bca2b696f3547ba42426e58129d76f64ef 100644
--- a/externals/moonlib/sfread2~.c
+++ b/externals/moonlib/sfread2~.c
@@ -317,7 +317,7 @@ static void sfread_open(t_sfread *x,t_symbol *filename)
     /* close the old file */
 
     if (x->x_mapaddr) munmap(x->x_mapaddr,x->x_size);
-    if (x->x_fd >= 0) close(x->x_fd);
+    if (x->x_fd >= 0) sys_close(x->x_fd);
 
     /*if ((x->x_fd = open(fname,O_RDONLY)) < 0)*/
     //post("fname: %s",fname);
diff --git a/externals/tb/sndfiler/src/file_input.c b/externals/tb/sndfiler/src/file_input.c
index 79ad27e37d769ce3e7e5b3b95d5b907408ae192a..210a0806072b56cce73834bd01994e3d8ec330f5 100644
--- a/externals/tb/sndfiler/src/file_input.c
+++ b/externals/tb/sndfiler/src/file_input.c
@@ -27,12 +27,12 @@ int check_fileformat(t_symbol* file)
     OggVorbis_File vorbisfile;
 
     // partially opens a vorbis file to test for Vorbis-ness
-    if( !(fp = fopen(file->s_name, "r")) )
+    if( !(fp = sys_fopen(file->s_name, "r")) )
         return -1;
 
     if( ov_test(fp, &vorbisfile, NULL, 0) < 0 )
     {
-        fclose(fp);
+        sys_fclose(fp);
         return USE_LIBSNDFILE;
     }
 
@@ -145,12 +145,12 @@ int read_libvorbisfile(t_float** helper_arrays, int channel_count, int seek,
     OggVorbis_File vorbisfile;
     vorbis_info *info;
 
-    if( !(fp = fopen(file->s_name, "r")) )
+    if( !(fp = sys_fopen(file->s_name, "r")) )
         return -1;
 
     if( ov_open(fp, &vorbisfile, NULL, 0) < 0 )
     {
-        fclose(fp);
+        sys_fclose(fp);
         return -1;
     }
 
diff --git a/pd/extra/bonk~/bonk~.c b/pd/extra/bonk~/bonk~.c
index f8b982553e24e5f7b12c06486f09d0d6f4fcb8c5..f1b3bae7a96f7e62e411cc9be75edb964401e1f8 100644
--- a/pd/extra/bonk~/bonk~.c
+++ b/pd/extra/bonk~/bonk~.c
@@ -1150,7 +1150,7 @@ static void bonk_write(t_bonk *x, t_symbol *s)
         buf, MAXPDSTRING);
     sys_bashfilename(buf, buf);
 
-    if (!(fd = fopen(buf, "w")))
+    if (!(fd = sys_fopen(buf, "w")))
     {
         post("%s: couldn't create", s->s_name);
         return;
diff --git a/pd/src/d_soundfile.c b/pd/src/d_soundfile.c
index e76cbad8c77574cb19bba228cd187453a801ebd7..e59b558f7778e5dd3577d4151e285f33b75e2f67 100644
--- a/pd/src/d_soundfile.c
+++ b/pd/src/d_soundfile.c
@@ -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;
diff --git a/pd/src/m_binbuf.c b/pd/src/m_binbuf.c
index 3a86bfb37fcffeaa7a613ce2d916f4e35440d6f8..53f07c4c74daa6722456c7168f968ee1d9d1f690 100644
--- a/pd/src/m_binbuf.c
+++ b/pd/src/m_binbuf.c
@@ -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);
diff --git a/pd/src/s_file.c b/pd/src/s_file.c
index acc8fa447598a7f9c026b84de807c623c8712a7e..be8b87958b361b1f40424a41f4e3030f43047b12 100644
--- a/pd/src/s_file.c
+++ b/pd/src/s_file.c
@@ -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;
diff --git a/pd/src/s_loader.c b/pd/src/s_loader.c
index 7039aa4b9a5f8509f3ac8e2fd4cf647dbe9b87aa..d927daa2964dcc75b72ace5e5797bd29f69a9bf8 100644
--- a/pd/src/s_loader.c
+++ b/pd/src/s_loader.c
@@ -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)))
         {
diff --git a/pd/src/s_main.c b/pd/src/s_main.c
index 975e42dc97c9d9ae7c9d5284dc1f932e00163ff2..62ad4dc69ab4f64d511db9bfa4ff1a052d79625d 100644
--- a/pd/src/s_main.c
+++ b/pd/src/s_main.c
@@ -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);
     }
diff --git a/pd/src/s_path.c b/pd/src/s_path.c
index 82df1fcce09135a73fa8a7bdebce750287e9f132..3582626f785fac06d5c35ffb05eb4de104930d93 100644
--- a/pd/src/s_path.c
+++ b/pd/src/s_path.c
@@ -357,7 +357,7 @@ int sys_trytoopenone(const char *dir, const char *name, const char* ext,
 
     DEBUG(post("looking for %s",dirresult));
         /* see if we can open the file for reading */
-    if ((fd=open(dirresult,O_RDONLY | MSWOPENFLAG(bin))) >= 0)
+    if ((fd = sys_open(dirresult,O_RDONLY | MSWOPENFLAG(bin))) >= 0)
     {
             /* in unix, further check that it's not a directory */
 #ifdef HAVE_UNISTD_H