UniqueFile OpenFile(const char* filename, int omode, mode_t pmode) { if(UniqueFile p_ifile{uopen(filename, omode, pmode)}) return p_ifile; else ystdex::throw_error<FileOperationFailure>(errno, "Failed opening file '" + string(filename) + "'."); }
void js_open(_js *joy) { joy->fd = 0; if (joy->dev[0] && ustrcmp(joy->dev, uL("NULL"))) { joy->fd = uopen(joy->dev, O_RDONLY | O_NONBLOCK); if (joy->fd < 0) { joy->fd = 0; } } }
void consinit(int dev, int speed) { struct linux_termios termios; int fd; switch (dev) { case CONSDEV_COM0: iodev = dev; break; case CONSDEV_GLASS: default: glass_console: iodev = CONSDEV_GLASS; break; } if (infd >= 0 && infd == outfd) { uclose(infd); infd = 0; outfd = 1; } if (iodev == CONSDEV_GLASS) { infd = 0; outfd = 1; strlcpy(bi_cons.devname, "glass", sizeof(bi_cons.devname)); bi_cons.addr = -1; bi_cons.speed = -1; } else { fd = uopen(comdevname[iodev - CONSDEV_COM0], LINUX_O_RDWR); if (fd < 0) goto glass_console; infd = outfd = fd; /* set speed */ linux_tcgetattr(fd, &termios); if (linux_cfsetspeed(&termios, speed) < 0) { speed = 9600; if (linux_cfsetspeed(&termios, speed) < 0) goto glass_console; } if (linux_tcsetattr(fd, LINUX_TCSETS, &termios) < 0) goto glass_console; snprintf(bi_cons.devname, sizeof(bi_cons.devname), "com%d", iodev - CONSDEV_COM0); bi_cons.addr = -1; bi_cons.speed = speed; } BI_ADD(&bi_cons, BTINFO_CONSDEV, sizeof(bi_cons)); }
int main () { FILE *fp; /* %e */ memset (&v, ~0, sizeof(v)); fp = uopen (PSTR ("1.0\0002e3"), 7); vrslt = fscanf (fp, "%e%c%e", & v.x, v.s, & v.y); ASSERT (vrslt == 3); ASSERT (v.x == 1.0 && !v.s[0] && v.y == 2e3); return 0; }
BYTE js_is_connected(int dev) { uTCHAR path_dev[30]; int fd; usnprintf(path_dev, usizeof(path_dev), uL("" JS_DEV_PATH "%d"), dev); if ((fd = uopen(path_dev, O_RDONLY | O_NONBLOCK)) < 0) { return (EXIT_ERROR); } close(fd); return (EXIT_OK); }
uTCHAR *js_name_device(int dev) { static uTCHAR name[128]; uTCHAR path_dev[30]; int fd; umemset(name, 0x00, usizeof(name)); usnprintf(path_dev, usizeof(path_dev), uL("" JS_DEV_PATH "%d"), dev); fd = uopen(path_dev, O_RDONLY | O_NONBLOCK); if (uioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0) { ustrncpy(name, uL("Not connected"), usizeof(name)); } close(fd); return((uTCHAR *) name); }
MappedFile::MappedFile(const char* path) : fd(uopen(path, O_RDONLY, S_IRUSR | S_IWUSR)) { ::fstat(fd, &st); #if YCL_DS addr = new ystdex::byte[st.st_size]; ::read(fd, addr, st.st_size); #elif YCL_MinGW32 // const auto p(::mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0))); const auto p(map_file(st.st_size, fd)); if(p == MAP_FAILED) throw std::runtime_error("Mapping failed."); // TODO: Create specific exception type. addr = static_cast<ystdex::byte*>(p); #else # error "Unsupported platform found." #endif }
void com_init(struct consdev *cn) { struct termios t; int unit = minor(cn->cn_dev); if (unit >= NCOM) return; if (com_fd != -1) uclose(com_fd); com_fd = uopen(compath[unit], O_RDWR); if (com_fd == -1) return; if (tcgetattr(com_fd, &t) == 0) { cfmakeraw(&t); cfsetspeed(&t, (speed_t)com_speed); (void)tcsetattr(com_fd, TCSAFLUSH, &t); } }
static int zboot_exec(int fd, u_long *marks, int flags) { char buf[512]; char *p; int tofd; int sz; int i; /* XXX cheating here by assuming that Xboot() was called before. */ tofd = uopen(_PATH_ZBOOT, O_WRONLY); if (tofd == -1) { printf("%s: can't open (errno %d)\n", _PATH_ZBOOT, errno); return 1; } p = cmd.path; for (; *p != '\0'; p++) if (*p == ':') { strlcpy(buf, p+1, sizeof(buf)); break; } if (*p == '\0') strlcpy(buf, cmd.path, sizeof(buf)); p = buf; for (; *p == '/'; p++) ; sz = strlen(p); if (uwrite(tofd, p, sz) != sz) { printf("zboot_exec: argument write error\n"); goto err; } buf[0] = ' '; buf[1] = '-'; if (uwrite(tofd, buf, 2) != 2) { printf("zboot_exec: argument write error\n"); goto err; } i = (cmd.argc > 1 && cmd.argv[1][0] != '-') ? 2 : 1; for (; i < cmd.argc; i++) { p = cmd.argv[i]; if (*p == '-') p++; sz = strlen(p); if (uwrite(tofd, p, sz) != sz) { printf("zboot_exec: argument write error\n"); goto err; } } /* Select UART unit for serial console. */ if (cn_tab && major(cn_tab->cn_dev) == 12) { buf[0] = '0' + minor(cn_tab->cn_dev); if (uwrite(tofd, buf, 1) != 1) { printf("zboot_exec: argument write error\n"); goto err; } } /* Commit boot arguments. */ uclose(tofd); tofd = uopen(_PATH_ZBOOT, O_WRONLY); if (tofd == -1) { printf("%s: can't open (errno %d)\n", _PATH_ZBOOT, errno); return 1; } if (lseek(fd, 0, SEEK_SET) != 0) { printf("%s: seek error\n", _PATH_ZBOOT); goto err; } while ((sz = read(fd, buf, sizeof(buf))) == sizeof(buf)) { if ((sz = uwrite(tofd, buf, sz)) != sizeof(buf)) { printf("%s: write error\n", _PATH_ZBOOT); goto err; } } if (sz < 0) { printf("zboot_exec: read error\n"); goto err; } if (sz >= 0 && uwrite(tofd, buf, sz) != sz) { printf("zboot_exec: write error\n"); goto err; } uclose(tofd); return 0; err: uclose(tofd); return 1; }
int main(int argc, char **argv) { int i, j, ntimes, err, flag, strl; double stim, read_tim, write_tim; double min_read_tim, min_write_tim, read_bw, write_bw; upcio_file_t *fh; upc_flag_t sync = 0; char *filename; shared int *buf; shared char *gfilename; shared int *len; ntimes=1; /* process 0 takes the file name as a command-line argument and broadcasts it to other processes */ len = (shared int *) upc_all_alloc(1, sizeof(int)); upc_barrier; if (!MYTHREAD) { i = 1; while ((i < argc) && strcmp("-fname", *argv)) { i++; argv++; } if (i >= argc) { fprintf(stderr, "\n*# Usage: perf -fname filename\n\n"); upc_global_exit(-1); } argv++; strl = strlen(*argv); upc_memput(len, &strl, sizeof(int)); } upc_barrier; upc_memget(&strl, len, sizeof(int)); upc_barrier; gfilename = (shared char *) upc_all_alloc(1,sizeof(char)*(strl)); if (!MYTHREAD) { upc_memput(gfilename, *argv, strl); fprintf(stderr, "Access size per process = %d bytes, ntimes = %d\n", SIZE, ntimes); } upc_barrier; filename = (char *) malloc(sizeof(char)*(strl+1)); upc_memget(filename, gfilename, strl); filename[strl] = '\0'; /* allocate the shared buf on each thread this is for shared w/r with INDIVIDUAL FP */ buf = (shared int *) upc_global_alloc(1,SIZE); upc_barrier; min_read_tim=0.0; min_write_tim=0.0; upc_barrier; fh = uopen( filename, 0); for (j=0; j<ntimes; j++) { upc_barrier; stim = UPC_Wtime(); upc_all_fseek(fh, MYTHREAD*SIZE + SIZE*THREADS*j, UPC_SEEK_SET); err = upc_all_fwrite_shared(fh, buf, BLOCK, SIZE, sizeof(unsigned char), sync); if( err == -1 ) { fprintf(stderr, "TH%2d: Error in write\n", MYTHREAD); break; } write_tim = UPC_Wtime() - stim; min_write_tim += write_tim; } upc_all_fclose(fh); upc_all_fsync(fh); min_write_tim /= ntimes; upc_barrier; fh = uopen( filename, 1); for (j=0; j<ntimes; j++) { upc_barrier; stim = UPC_Wtime(); upc_all_fseek(fh, MYTHREAD*SIZE + SIZE*THREADS*j, UPC_SEEK_SET); err = upc_all_fread_shared(fh, buf, BLOCK, SIZE, sizeof(unsigned char), sync); if( err == -1 ) { fprintf(stderr, "TH%2d: Error in read\n", MYTHREAD); break; } read_tim = UPC_Wtime() - stim; min_read_tim += read_tim; } upc_all_fclose(fh); min_read_tim /= ntimes; upc_barrier; if (!MYTHREAD) { read_bw = (SIZE*THREADS*ntimes)/(min_read_tim*1024.0*1024.0); write_bw = (SIZE*THREADS*ntimes)/(min_write_tim*1024.0*1024.0); printf("TH: %d - Write bandwidth with a prior file sync = %f Mbytes/sec\n", MYTHREAD, write_bw); printf("TH: %d - Read bandwidth with a prior file sync = %f Mbytes/sec\n", MYTHREAD, read_bw); } upc_barrier; /* only thread 0 clean up the single shared buf */ if(!MYTHREAD) { upc_free(buf); upc_free(gfilename); upc_free(len); } free(filename); return 0; }
int BLI_open(const char *filename, int oflag, int pmode) { return uopen(filename, oflag, pmode); }