uint STDCALL gcabd_iscabinet( HFDI hfdi, pubyte cabfile, pdecabinfo pdecab ) { int hf; uint ret; again: hf = file_open( cabfile, _O_BINARY | _O_RDONLY | _O_SEQUENTIAL, 0 ); if ( hf == -1 ) { (( gentee_call )pdecab->call)( pdecab->fncsysnotify, &ret, FLN_ERROPEN, cabfile, pdecab ); if ( ret ) goto again; return 0; } ret = FDIIsCabinet( hfdi, hf, &pdecab->fdic ); file_close( hf ); return ret; }
static int read_file(char *filename) { int ret; struct file *fp; unsigned long long offset; unsigned char buff[1024+1]; fp = file_open(filename, O_RDWR|O_LARGEFILE, 0); if(fp){ offset = 0; while((ret = file_read(fp, offset, buff, 1024))){ buff[ret] = '\0'; offset += ret; printk("%s", buff); } file_close(fp); }else{ printk("file_open faild\n"); } return 0; }
bool remove (const char *file) { if (not_valid(file)) exit (-1); lock_acquire(&file_lock); /* In case the file is opened. First check its existence. */ struct file *f = filesys_open (file); bool result; if (f == NULL) result = false; else { file_close (f); result = filesys_remove (file); } lock_release(&file_lock); return result; }
static int _can_read_file(const char *fn) { BD_FILE_H *fp; if (!fn) { return 0; } fp = file_open(fn, "rb"); if (fp) { uint8_t b; int result = (int)file_read(fp, &b, 1); file_close(fp); if (result == 1) { return 1; } BD_DEBUG(DBG_BDJ | DBG_CRIT, "Error reading %s\n", fn); } return 0; }
/* open door file for the given JVM */ static int open_door(pid_t pid) { char path[PATH_MAX + 1]; int fd; sprintf(path, DOOR_FILE_PATTERN, pid); fd = file_open(path, O_RDONLY); if (fd < 0) { set_jvm_error(JVM_ERR_CANT_OPEN_DOOR); print_debug("cannot open door file %s\n", path); return -1; } print_debug("opened door file %s\n", path); if (check_permission(path) != 0) { set_jvm_error(JVM_ERR_DOOR_FILE_PERMISSION); print_debug("check permission failed for %s\n", path); file_close(fd); fd = -1; } return fd; }
static int file_ftruncate(struct file_info *file, int fd, off_t new_length) { if (ftruncate(fd, new_length) == -1) { CHECK(errno = ENOSPC); file->no_space_error = 1; /* Delete errored files */ if (!file->deleted) { struct fd_info *fdi; fdi = file->fds; while (fdi) { file_close(fdi); fdi = file->fds; } file_delete(file); } return 0; } return 1; }
/* Close a file. */ static void sys_close (int fd) { struct user_file *f; #if PRINT_DEBUG printf ("[SYSCALL] SYS_CLOSE: fd: %d\n", fd); #endif f = file_by_fid (fd); if (f == NULL) sys_exit (-1); lock_acquire (&file_lock); list_remove (&f->thread_elem); file_close (f->file); free (f); lock_release (&file_lock); }
/* detach the givenb JVM */ int jvm_detach(jvm_t* jvm) { if (jvm) { int res; if (jvm->door_fd != -1) { if (file_close(jvm->door_fd) != 0) { set_jvm_error(JVM_ERR_CANT_CLOSE_DOOR); res = -1; } else { clear_jvm_error(); res = 0; } } free(jvm); return res; } else { set_jvm_error(JVM_ERR_NULL_PARAM); print_debug("jvm_t* is NULL\n"); return -1; } }
/* * sys_dup2 * */ int sys_dup2(int oldfd, int newfd, int *retval) { if ((oldfd < 0) || (oldfd >= __OPEN_MAX) || (newfd < 0) || (newfd >= __OPEN_MAX)) { return EBADF; } // Check oldfd is a valid file handle in filetable struct filetable *ft = curthread->t_filetable; spinlock_acquire(&ft->filetable_lock); if (ft->ft_entries[oldfd] == NULL) { return EBADF; } // Do nothing if old fd is the same as newfd if(oldfd == newfd) { *retval = newfd; spinlock_release(&ft->filetable_lock); return 0; } // return ENFILE error code if the process's file table was full if(ft->ft_entries[oldfd]->count > __OPEN_MAX) { spinlock_release(&ft->filetable_lock); return ENFILE; } // If newfd names an already-open file, that file is closed. if (ft->ft_entries[newfd] != NULL) { file_close(newfd); } ft->ft_entries[newfd] = ft->ft_entries[oldfd]; ft->ft_entries[newfd]->count += 1; *retval = newfd; spinlock_release(&ft->filetable_lock); return 0; }
static void file_write(struct file_info *file, int fd) { off_t offset; size_t size, actual; unsigned seed; int truncate = 0; get_offset_and_size(file, &offset, &size); seed = tests_random_no(10000000); actual = file_write_data(file, fd, offset, size, seed); if (offset + actual <= file->length && shrink) /* 1 time in 100, when shrinking truncate after the write */ if (tests_random_no(100) == 0) truncate = 1; if (actual != 0) file_write_info(file, offset, actual, seed); /* Delete errored files */ if (file->no_space_error) { if (!file->deleted) { struct fd_info *fdi; fdi = file->fds; while (fdi) { file_close(fdi); fdi = file->fds; } file_delete(file); } return; } if (truncate) { size_t new_length = offset + actual; if (file_ftruncate(file, fd, new_length)) file_truncate_info(file, new_length); } }
static ssize_t irmotion_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int value; if (sysfs_streq(buf, "1")) value = true; else if (sysfs_streq(buf, "0")) value = false; else { printk(KERN_ERR "%s (%d) : invalid value %d\n", __func__, __LINE__,*buf); return size; } if(value == 1){ printk(KERN_INFO "%s (%d) : gesture enable\n", __func__, __LINE__); #ifdef IRMOTION_TRACE_LOG if(LogON == 1){ filp = file_open(IRMOTION_LOGFILE,O_CREAT | O_RDWR | O_APPEND | O_LARGEFILE,0777); if(filp != NULL){ TraceLogON = 1; } } #endif pac7620_irmotion_enable(); }else if(value == 0){ printk(KERN_INFO "%s (%d) : gesture disable\n", __func__, __LINE__); pac7620_irmotion_disable(); #ifdef IRMOTION_TRACE_LOG if(LogON == 1){ file_write(filp, filp->f_pos, "========================================\n", 41); file_close(filp); } TraceLogON = 0; #endif } return size; }
void fpga_pgm(uint8_t* filename) { int MAXRETRIES = 10; int retries = MAXRETRIES; int j=0; do { set_prog_b(0); uart_putc('P'); set_prog_b(1); loop_until_bit_is_set(PIND, PD7); uart_putc('p'); UINT bytes_read; // open configware file file_open(filename, FA_READ); if(file_res) { uart_putc('?'); uart_putc(0x30+file_res); return; } for (;;) { if(!(j++ % 8)) { toggle_pwr_led(); } bytes_read = file_read(); if (file_res || bytes_read == 0) break; // error or eof for(int i=0; i<bytes_read; i++) { FPGA_SEND_BYTE_SERIAL(file_buf[i]); } } file_close(); _delay_ms(100); } while (!fpga_get_done() && retries--); if(!fpga_get_done()) { dprintf("FPGA failed to configure after %d tries.\n", MAXRETRIES); _delay_ms(50); led_panic(); } fpga_postinit(); }
/*! Close an fd */ void close(uint32_t fd) { /* first find the file of this fd. */ struct f_info* f = findfile(fd); /* Close the file, remove the f_info from the f_lst, and then * free this f_info. Update f_count accordingly. */ lock_acquire(&filesys_lock); if (f->isdir) dir_close(f->d); else file_close(f->f); list_remove(&f->elem); free(f); struct thread* t = thread_current(); --(t->f_count); lock_release(&filesys_lock); }
// read data from source file into ringbuffer // void reader(char* srcpath) { int srcfd = file_open_read(srcpath); // open source file for reading int bufpos = 0; // next free space in ringbuffer int rcount; // number of bytes read on last iteration do { sem_wait(&buf_full); // wait until buffer is not full // read from sourcefile into buffer rcount = file_read(srcfd, buffer[bufpos], sizeof(buffer[bufpos])); // store number of bytes read and advance write head buffill[bufpos] = rcount; bufpos = (bufpos + 1) % BUFSIZE; sem_post(&buf_empty); // increase number of cells written to buffer (unblock writer) } while(rcount > 0); // abort on EOF (zero bytes read from source) file_close(srcfd); }
int file_reset(int remove) { int result = 0; file_close(); snprintf(g_filename, PATH_SIZE, "%s/synchro_simple.txt", g_tmp_dir); if (remove) { utf8_unlink(g_filename); } g_file_full = FALSE; g_total_op = 0; g_fd = utf8_fopen(g_filename, "ab"); if (!g_fd) { ERROR_LOG("Cannot open file %s. Error(%d): %s\n", g_filename, errno, strerror(errno)); result = errno; goto cleanup; } cleanup: return result; }
int load_package_signature(struct pkg *pkg, int dirfd) { struct file_t file; _cleanup_free_ char *signame = joinstring(pkg->filename, ".sig", NULL); _cleanup_close_ int fd = openat(dirfd, signame, O_RDONLY); if (fd < 0) return -1; if (file_from_fd(&file, fd) < 0) return -1; base64_encode((unsigned char **)&pkg->base64sig, (const unsigned char *)file.mmap, file.st.st_size); if (file.st.st_mtime > pkg->mtime) file.st.st_mtime = pkg->mtime; file_close(&file); return 0; }
int file_make( t_file *file) { if ( file_init( file)) { file->file = fopen( file->path, "w"); if( file->file) { file_close( file); return 1; } else { printf("[FILE] Error can't create %s\n,", file->path); return 0; } } else { return 0; } }
bool test_file_close (Test *test) { Directory *directory; File *file; char *path; TITLE (); CATCH (!(path = directory_current_path ())); CATCH (!string_append (&path, "/stage/open")); /* d stage/open f f1 */ CATCH (!(directory = directory_open (path))); string_destroy (path); CATCH (!directory_read (directory)); CATCH (!(file = directory_find_file (directory, "f1"))); file_close (file); directory_close (directory); PASS (); }
static void writeseg(const OEMCHAR *fname, UINT32 addr, UINT limit) { FILEH fh; UINT size; UINT8 buf[0x400]; // Stack 0x1000 -> 0x400 fh = file_create_c(fname); if (fh == FILEH_INVALID) { return; } limit = min(limit, 0xffff); limit++; while(limit) { size = min(limit, sizeof(buf)); MEML_READS(addr, buf, size); file_write(fh, buf, size); addr += size; limit -= size; } file_close(fh); }
/* * Actually read the savefile */ int rd_savefile_old(void) { errr err; /* Open savefile */ safe_setuid_grab(); fff = file_open(savefile, MODE_READ, -1); safe_setuid_drop(); /* Paranoia */ if (!fff) return (-1); /* Call the sub-function */ err = rd_savefile_new_aux(); /* Close the file */ file_close(fff); /* Result */ return (err); }
/* write a string to the terminal */ int nf_puts(const char *s) { int fd; ssize_t len; len = strlen(s); fd = vfs_open("/dev/vt"); if (fd < 0) return -1; if (file_write(fd, (void*)s, len) != len) return -1; if (file_close(fd)) return -1; return len; }
fsal_status_t lru_cleanup(struct fsal_obj_handle * obj_hdl, lru_actions_t requests) { fsal_status_t status = { ERR_FSAL_NO_ERROR, 0 }; struct glusterfs_handle *objhandle = container_of(obj_hdl, struct glusterfs_handle, handle); #ifdef GLTIMING struct timespec s_time, e_time; now(&s_time); #endif if (objhandle->glfd != NULL) { status = file_close(obj_hdl); } #ifdef GLTIMING now(&e_time); latency_update(&s_time, &e_time, lat_lru_cleanup); #endif return status; }
static int _bdrom_have_file(void *p, const char *dir, const char *file) { struct dec_dev *dev = (struct dec_dev *)p; BD_FILE_H *fp; char *path; path = str_printf("%s" DIR_SEP "%s", dir, file); if (!path) { return 0; } fp = dev->pf_file_open_bdrom(dev->file_open_bdrom_handle, path); X_FREE(path); if (fp) { file_close(fp); return 1; } return 0; }
int main (int argc, char **argv) { struct file f; char *line; int i; int n; n = 0; for (i = 1; i < argc; i++) { file_open (&f, argv[i]); while ((line = file_readline (&f))) { check_parse (line); n++; } file_close (&f); } url_free (&url); printf ("Tested %d urls.\n", n); }
/* set the background image */ void gui_set_bg(const char *path) { int fd; uint16_t w, h; fd = vfs_open(path); if (fd < 0) return; w = h = 0; (void)file_read(fd, &w, sizeof(w)); (void)file_read(fd, &h, sizeof(h)); if (w != GUI_WIDTH || h != GUI_HEIGHT) return; (void)file_read(fd, gui_bg_buffer, sizeof(gui_bg_buffer)); (void)file_close(fd); gui_redraw(); }
//! //! This function closes a file. //! //! @param fd file descriptor. //! //! @return int : -1 if error, 0 otherwise //! int close(int fd) { if (fd < 0) { return (-1); } // take the mutex for nav access fsaccess_take_mutex(); nav_select( fd ); file_close(); fsaccess_free_nav_id(fd); // give the mutex for nav access fsaccess_give_mutex(); return (0); }
int load_bios(char *fn,u8 *dest,int size) { int fp; char tmp[1024]; sprintf(tmp,"%s/%s",curdir,fn); if((fp = file_open(tmp,"rb")) == -1) { strcat(fn,".gz"); if((fp = file_open(tmp,"rb")) == -1) { log_message("failed to load bios '%s'\n",fn); return(1); } } if(file_read(fp,dest,size) != (size)) { log_message("failed to load '%s', rom is too small\n",fn); return(2); } file_close(fp); log_message("found '%s'\n",fn); return(0); }
/* Randomly select something to do with an open file */ static void operate_on_open_file(struct fd_info *fdi) { size_t r; r = tests_random_no(1000); if (shrink && r < 5) file_truncate(fdi->file, fdi->fd); else if (r < 21) file_close(fdi); else if (shrink && r < 121 && !fdi->file->deleted) file_delete(fdi->file); else { file_write(fdi->file, fdi->fd); if (r >= 999) { if (tests_random_no(100) >= 50) CHECK(fsync(fdi->fd) != -1); else CHECK(fdatasync(fdi->fd) != -1); } } }
static void trfh_close(void) { FILEH fh; fh = tracewin.fh; tracewin.fh = FILEH_INVALID; if (fh != FILEH_INVALID) { #if defined(FILEBUFSIZE) UINT size = filebufpos & (FILEBUFSIZE - 1); #if defined(FILELASTBUFONLY) if (filebufpos >= FILEBUFSIZE) { file_write(fh, filebuf + size, FILEBUFSIZE - size); } #endif if (size) { file_write(fh, filebuf, size); } #endif file_close(fh); } }
/* Save the user configuration. */ unsigned config_save(void) { char *tmpprefix = NULL, *tmppath = NULL; struct config_save_status status; int i; int ret = 0; if (read_only) return 1; asprintf(&tmpprefix, "%s/%s", get_tempdir(), CONF_PATH_NAME); if ((tmppath = new_tempfile(tmpprefix)) == NULL) goto cleanup; status.fp = fopen(tmppath, "w"); if (!status.fp) goto cleanup; memset(status.done, 0, sizeof(status.done)); config_file_walk(config_save_cb, config_save_junk_cb, (void *)&status); /* Set variables that were missing from the configuration file. */ for (i = 0; i < ARRAY_SIZE(confmap); i++) { if (!status.done[i]) config_save_cb(confmap[i].key, NULL, &status); } file_close(status.fp, __FILE_POS__); if (io_file_cp(tmppath, path_conf)) unlink(tmppath); ret = 1; cleanup: mem_free(tmpprefix); mem_free(tmppath); return ret; }