oblique_mc

Monte Carlo in Single Layer Biological Tissue
git clone anongit@rnpnr.xyz:oblique_mc.git
Log | Files | Refs | Feed | README | LICENSE

posix.c (864B)


      1 #include <fcntl.h>
      2 #include <unistd.h>
      3 
      4 #define OS_READ     O_RDONLY
      5 #define OS_WRITE    (O_WRONLY | O_CREAT | O_TRUNC)
      6 #define OS_RW       O_RDWR
      7 #define OS_SEEK_BEG SEEK_SET
      8 #define OS_SEEK_CUR SEEK_CUR
      9 #define OS_SEEK_END SEEK_END
     10 
     11 typedef int os_file;
     12 
     13 static os_file
     14 os_open(s8 path, int flags)
     15 {
     16 	os_file f;
     17 	f = open((char *)path.data, flags, 0600);
     18 	if (f == -1)
     19 		die("rip can't open output file: %s\n", path.data);
     20 	return f;
     21 }
     22 
     23 static void
     24 os_write(os_file f, s8 s)
     25 {
     26 	if (write(f, s.data, s.len) == -1)
     27 		die("can't write to file\n");
     28 }
     29 
     30 static void
     31 os_close(os_file f)
     32 {
     33 	close(f);
     34 }
     35 
     36 static void
     37 os_seek(os_file f, size off, int whence)
     38 {
     39 	lseek(f, off, whence);
     40 }
     41 
     42 static u32
     43 os_get_core_count(void)
     44 {
     45 	return sysconf(_SC_NPROCESSORS_ONLN);
     46 }
     47 
     48 static void
     49 os_pause(void)
     50 {
     51 	/* not useful here since the user will run from command line */
     52 	return;
     53 }