FILE *fopen(const char *pathname, const char *mode) { static FILE * (*real_fopen)(const char *pathname, const char *mode) = NULL; const char *p; FILE *ret; GET_PATH(fopen); if (p) { ret = real_fopen(p, mode); PUT_PATH(NULL); } return real_fopen(pathname, mode); }
static int _write(mtd_dev_t *dev, const void *buff, uint32_t addr, uint32_t size) { mtd_native_dev_t *_dev = (mtd_native_dev_t*) dev; size_t mtd_size = dev->sector_count * dev->pages_per_sector * dev->page_size; DEBUG("mtd_native: write from 0x%" PRIx32 " count %" PRIu32 "\n", addr, size); if (addr + size > mtd_size) { return -EOVERFLOW; } if (((addr % dev->page_size) + size) > dev->page_size) { return -EOVERFLOW; } FILE *f = real_fopen(_dev->fname, "r+"); if (!f) { return -EIO; } real_fseek(f, addr, SEEK_SET); for (size_t i = 0; i < size; i++) { uint8_t c = real_fgetc(f); real_fseek(f, -1, SEEK_CUR); real_fputc(c & ((uint8_t*)buff)[i], f); } real_fclose(f); return size; }
static int _erase(mtd_dev_t *dev, uint32_t addr, uint32_t size) { mtd_native_dev_t *_dev = (mtd_native_dev_t*) dev; size_t mtd_size = dev->sector_count * dev->pages_per_sector * dev->page_size; size_t sector_size = dev->pages_per_sector * dev->page_size; DEBUG("mtd_native: erase from sector %" PRIu32 " count %" PRIu32 "\n", addr, size); if (addr + size > mtd_size) { return -EOVERFLOW; } if (((addr % sector_size) != 0) || ((size % sector_size) != 0)) { return -EOVERFLOW; } FILE *f = real_fopen(_dev->fname, "r+"); if (!f) { return -EIO; } real_fseek(f, addr, SEEK_SET); for (size_t i = 0; i < size; i++) { real_fputc(0xff, f); } real_fclose(f); return 0; }
FILE *fopen(const char *path, const char *mode) { if (!libc_handle) initialize(); FILE *fp = real_fopen(path, mode); if (fp) real_setvbuf(fp, NULL, _IONBF, 0); return fp; }
bfd * bfd_fopen (const char *filename, const char *target, const char *mode, int fd) { bfd *nbfd; const bfd_target *target_vec; nbfd = _bfd_new_bfd (); if (nbfd == NULL) return NULL; target_vec = bfd_find_target (target, nbfd); if (target_vec == NULL) { _bfd_delete_bfd (nbfd); return NULL; } #ifdef HAVE_FDOPEN if (fd != -1) nbfd->iostream = fdopen (fd, mode); else #endif nbfd->iostream = real_fopen (filename, mode); if (nbfd->iostream == NULL) { bfd_set_error (bfd_error_system_call); _bfd_delete_bfd (nbfd); return NULL; } /* OK, put everything where it belongs. */ nbfd->filename = filename; /* Figure out whether the user is opening the file for reading, writing, or both, by looking at the MODE argument. */ if ((mode[0] == 'r' || mode[0] == 'w' || mode[0] == 'a') && mode[1] == '+') nbfd->direction = both_direction; else if (mode[0] == 'r') nbfd->direction = read_direction; else nbfd->direction = write_direction; if (! bfd_cache_init (nbfd)) { _bfd_delete_bfd (nbfd); return NULL; } nbfd->opened_once = TRUE; /* If we opened the file by name, mark it cacheable; we can close it and reopen it later. However, if a file descriptor was provided, then it may have been opened with special flags that make it unsafe to close and reopen the file. */ if (fd == -1) bfd_set_cacheable (nbfd, TRUE); return nbfd; }
bool DiskFile::open(const char *mode /* = NULL */) { if(isopen()) close(); _fh = real_fopen(fullname(), mode ? mode : "rb"); return !!_fh; }
FILE* fopen(const char* name, const char* mode) { static FILE* (*real_fopen)(const char*, const char*) = NULL; if (!real_fopen) real_fopen = dlsym(RTLD_NEXT, "fopen"); if (!allowed(name, (mode[0] == 'r') ? 0 : O_CREAT)) { return NULL; } return real_fopen(name, mode); }
bool FileExists(const char *fn) { #ifdef _WIN32 void *fp = real_fopen(fn, "rb"); if(fp) { real_fclose(fp); return true; } return false; #else return access(fn, F_OK) == 0; #endif }
static int _init(mtd_dev_t *dev) { mtd_native_dev_t *_dev = (mtd_native_dev_t*) dev; DEBUG("mtd_native: init, filename=%s\n", _dev->fname); FILE *f = real_fopen(_dev->fname, "r"); if (!f) { DEBUG("mtd_native: init: creating file %s\n", _dev->fname); f = real_fopen(_dev->fname, "w+"); if (!f) { return -EIO; } size_t size = dev->sector_count * dev->pages_per_sector * dev->page_size; for (size_t i = 0; i < size; i++) { real_fputc(0xff, f); } } real_fclose(f); return 0; }
bool VFSFileReal::open(const char *mode /* = NULL */) { VFS_GUARD_OPT(this); if(isopen()) close(); dropBuf(true); _fh = real_fopen(fullname(), mode ? mode : "rb"); if(!_fh) return false; real_fseek((FILE*)_fh, 0, SEEK_END); _size = getpos(); real_fseek((FILE*)_fh, 0, SEEK_SET); return true; }
static int _read(mtd_dev_t *dev, void *buff, uint32_t addr, uint32_t size) { mtd_native_dev_t *_dev = (mtd_native_dev_t*) dev; size_t mtd_size = dev->sector_count * dev->pages_per_sector * dev->page_size; DEBUG("mtd_native: read from page %" PRIu32 " count %" PRIu32 "\n", addr, size); if (addr + size > mtd_size) { return -EOVERFLOW; } FILE *f = real_fopen(_dev->fname, "r"); if (!f) { return -EIO; } real_fseek(f, addr, SEEK_SET); size = real_fread(buff, 1, size, f); real_fclose(f); return size; }
FILE *fopen(const char *path, const char *mode) { int i; for (i = 0; ; i++) { if (!strcmp(valid_modes[i], mode)) break; if (!valid_modes[i][0]) die("fopen(%s): unsupported mode '%s'", path, mode); } int flags = mode[0] == 'w' ? O_WRONLY : O_RDONLY; if (flags == O_WRONLY) mode = "w+"; // Open read/write for hashing purposes struct hash path_hash; remember_hash_path(&path_hash, path); if (flags & O_WRONLY) action_open_write(path, &path_hash); else { // O_RDONLY if (!action_open_read(path, &path_hash)) { // File does not exist, no need to call fopen. errno = ENOENT; return NULL; } } FILE *file = real_fopen(path, mode); if (!file) { if (errno != ENOENT) die("fopen(%s) failed: %s", path, strerror(errno)); } else if (!strcmp(mode, "r+b")) die("fopen(%s): mode r+b is unsupported unless file doesn't exist"); fd_map_open(fileno(file), flags | WO_FOPEN, &path_hash); return file; }
FILE *fopen(const char *path, const char *mode) { const char *mock; bool allinone = false, logind = false; init_syms(); mock = getenv("VIR_CGROUP_MOCK_MODE"); if (mock) { if (STREQ(mock, "allinone")) allinone = true; else if (STREQ(mock, "logind")) logind = true; } if (STREQ(path, "/proc/mounts")) { if (STREQ(mode, "r")) { if (allinone) return fmemopen((void *)procmountsallinone, strlen(procmountsallinone), mode); else if (logind) return fmemopen((void *)procmountslogind, strlen(procmountslogind), mode); else return fmemopen((void *)procmounts, strlen(procmounts), mode); } else { errno = EACCES; return NULL; } } if (STREQ(path, "/proc/cgroups")) { if (STREQ(mode, "r")) { if (allinone) return fmemopen((void *)proccgroupsallinone, strlen(proccgroupsallinone), mode); else if (logind) return fmemopen((void *)proccgroupslogind, strlen(proccgroupslogind), mode); else return fmemopen((void *)proccgroups, strlen(proccgroups), mode); } else { errno = EACCES; return NULL; } } if (STREQ(path, "/proc/self/cgroup")) { if (STREQ(mode, "r")) { if (allinone) return fmemopen((void *)procselfcgroupsallinone, strlen(procselfcgroupsallinone), mode); else if (logind) return fmemopen((void *)procselfcgroupslogind, strlen(procselfcgroupslogind), mode); else return fmemopen((void *)procselfcgroups, strlen(procselfcgroups), mode); } else { errno = EACCES; return NULL; } } return real_fopen(path, mode); }
FILE * bfd_open_file (bfd *abfd) { abfd->cacheable = TRUE; /* Allow it to be closed later. */ if (open_files >= BFD_CACHE_MAX_OPEN) { if (! close_one ()) return NULL; } switch (abfd->direction) { case read_direction: case no_direction: abfd->iostream = (PTR) real_fopen (abfd->filename, FOPEN_RB); break; case both_direction: case write_direction: if (abfd->opened_once) { abfd->iostream = (PTR) real_fopen (abfd->filename, FOPEN_RUB); if (abfd->iostream == NULL) abfd->iostream = (PTR) real_fopen (abfd->filename, FOPEN_WUB); } else { /* Create the file. Some operating systems won't let us overwrite a running binary. For them, we want to unlink the file first. However, gcc 2.95 will create temporary files using O_EXCL and tight permissions to prevent other users from substituting other .o files during the compilation. gcc will then tell the assembler to use the newly created file as an output file. If we unlink the file here, we open a brief window when another user could still substitute a file. So we unlink the output file if and only if it has non-zero size. */ #ifndef __MSDOS__ /* Don't do this for MSDOS: it doesn't care about overwriting a running binary, but if this file is already open by another BFD, we will be in deep trouble if we delete an open file. In fact, objdump does just that if invoked with the --info option. */ struct stat s; if (stat (abfd->filename, &s) == 0 && s.st_size != 0) unlink_if_ordinary (abfd->filename); #endif abfd->iostream = (PTR) real_fopen (abfd->filename, FOPEN_WUB); abfd->opened_once = TRUE; } break; } if (abfd->iostream == NULL) bfd_set_error (bfd_error_system_call); else { if (! bfd_cache_init (abfd)) return NULL; } return (FILE *) abfd->iostream; }
return sinceLast; } extern "C" { /// create a functionpointer real_##FNAME that points to the real FNAME function #define GET_REAL(FNAME) \ typedef decltype(&FNAME) FPTR; \ static FPTR real_##FNAME = nullptr; \ if (!real_##FNAME) \ real_##FNAME = (FPTR)dlsym(RTLD_NEXT, #FNAME); FILE *fopen(__const char *__restrict __filename, __const char *__restrict __modes) { GET_REAL(fopen); FILE *fd = real_fopen(__filename, __modes); if (fd && logFileName != __filename) files().open(__filename, fileno(fd)); return fd; } FILE *fopen64(__const char *__restrict __filename, __const char *__restrict __modes) { GET_REAL(fopen64); FILE *fd = real_fopen64(__filename, __modes); if (fd && logFileName != __filename) files().open(__filename, fileno(fd)); return fd; } /// measure the given function call, store its result in res and the time in
/* * Copyright (c) 2008-2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * * static FILE * * wrap_fopen(const char *path, const char *mode) { * FILE * rc = 0; */ PSEUDO_STATBUF buf; int save_errno; int existed = (base_stat(path, &buf) != -1); rc = real_fopen(path, mode); save_errno = errno; if (rc) { int fd = fileno(rc); pseudo_debug(PDBGF_OP, "fopen '%s': fd %d <FILE %p>\n", path, fd, (void *) rc); if (base_fstat(fd, &buf) != -1) { if (!existed) { pseudo_client_op(OP_CREAT, 0, -1, -1, path, &buf); } pseudo_client_op(OP_OPEN, pseudo_access_fopen(mode), fd, -1, path, &buf); } else { pseudo_debug(PDBGF_CONSISTENCY, "fopen (fd %d) succeeded, but fstat failed (%s).\n", fd, strerror(errno)); pseudo_client_op(OP_OPEN, pseudo_access_fopen(mode), fd, -1, path, 0); } errno = save_errno; }