static int print_rename(const char *from, const char *to, void *user) { struct recv_args *r = user; char *full_from = path_cat(r->full_subvol_path, from); char *full_to = path_cat(r->full_subvol_path, to); printf("rename\t%s\t%s\n", from, to); free(full_from); free(full_to); return 0; }
static int process_utimes(const char *path, struct timespec *at, struct timespec *mt, struct timespec *ct, void *user) { int ret = 0; struct btrfs_receive *r = user; char *full_path = path_cat(r->full_subvol_path, path); struct timespec tv[2]; if (g_verbose >= 2) fprintf(stderr, "utimes %s\n", path); tv[0] = *at; tv[1] = *mt; ret = utimensat(AT_FDCWD, full_path, tv, AT_SYMLINK_NOFOLLOW); if (ret < 0) { ret = -errno; fprintf(stderr, "ERROR: utimes %s failed. %s\n", path, strerror(-ret)); goto out; } out: free(full_path); return ret; }
// Check whether the directory specified by catting the given base and path // exists // @return The resulting directory path, which should not be deleted and is // valid indefinitely. NULL is directory cannot be found. static const char* try_path(const char* base, const char* path, bool* out_found_notdir) { char composite[FILENAME_MAX]; char file[FILENAME_MAX]; path_cat(base, path, composite); if(pony_realpath(composite, file) != file) return NULL; struct stat s; int err = stat(file, &s); if(err == -1) return NULL; if(!S_ISDIR(s.st_mode)) { if(out_found_notdir != NULL) *out_found_notdir = true; return NULL; } return stringtab(file); }
static int process_write(const char *path, const void *data, u64 offset, u64 len, void *user) { int ret = 0; struct btrfs_receive *r = user; char *full_path = path_cat(r->full_subvol_path, path); u64 pos = 0; int w; ret = open_inode_for_write(r, full_path); if (ret < 0) goto out; while (pos < len) { w = pwrite(r->write_fd, (char*)data + pos, len - pos, offset + pos); if (w < 0) { ret = -errno; fprintf(stderr, "ERROR: writing to %s failed. %s\n", path, strerror(-ret)); goto out; } pos += w; } out: free(full_path); return ret; }
static int process_set_xattr(const char *path, const char *name, const void *data, int len, void *user) { int ret = 0; struct btrfs_receive *r = user; char *full_path = path_cat(r->full_subvol_path, path); if (g_verbose >= 2) { fprintf(stderr, "set_xattr %s - name=%s data_len=%d " "data=%.*s\n", path, name, len, len, (char*)data); } ret = lsetxattr(full_path, name, data, len, 0); if (ret < 0) { ret = -errno; fprintf(stderr, "ERROR: lsetxattr %s %s=%.*s failed. %s\n", path, name, len, (char*)data, strerror(-ret)); goto out; } out: free(full_path); return ret; }
static int print_truncate(const char *path, u64 size, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("truncate\t%llu\t%s\n", (unsigned long long)size, full_path); free(full_path); return 0; }
static int print_link(const char *path, const char *lnk, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("link\t%s\t%s\n", lnk, full_path); free(full_path); return 0; }
static int print_chmod(const char *path, u64 mode, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("chmod\t%llo\t%s\n", (unsigned long long)mode, full_path); free(full_path); return 0; }
/** * Gets absolute path by relative path * @param relative Relative or absolute path * @return Absolute path (Can be passed to free()) */ static char *getabsolutepath(const char *relative) { path_t *path = path_parse(relative); if (!path->root) { path_t *newpath = path_cat(workdir.path,path); path_destroy(path); path = newpath; } path_reject_dots(path); return path_output(path,NULL); }
static int print_remove_xattr(const char *path, const char *name, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("remove_xattr\t%s\t%s\n", full_path, name); free(full_path); return 0; }
static int print_rmdir(const char *path, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("rmdir\t%s\n", full_path); free(full_path); return 0; }
static int print_update_extent(const char *path, u64 offset, u64 len, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("update_extent\t%s\t%llu\t%llu\n", full_path, offset, len); free(full_path); return 0; }
static int print_chown(const char *path, u64 uid, u64 gid, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("chown\t%llu\t%llu\t%s\n", (unsigned long long)uid, (unsigned long long)gid, full_path); free(full_path); return 0; }
// Check whether the directory specified by catting the given base and path // exists // @return The resulting directory path, which should not be deleted and is // valid indefinitely. NULL is directory cannot be found. static const char* try_path(const char* base, const char* path) { char composite[FILENAME_MAX]; char file[FILENAME_MAX]; path_cat(base, path, composite); if(pony_realpath(composite, file) != file) return NULL; return stringtab(file); }
static int process_link(const char *path, const char *lnk, void *user) { int ret; struct btrfs_receive *r = user; char *full_path = path_cat(r->full_subvol_path, path); char *full_link_path = path_cat(r->full_subvol_path, lnk); if (g_verbose >= 2) fprintf(stderr, "link %s -> %s\n", path, lnk); ret = link(full_link_path, full_path); if (ret < 0) { ret = -errno; fprintf(stderr, "ERROR: link %s -> %s failed. %s\n", path, lnk, strerror(-ret)); } free(full_path); free(full_link_path); return ret; }
static int print_set_xattr(const char *path, const char *name, const void *data, int len, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("set_xattr\t%s\t%s\t%d\n", full_path, name, len); free(full_path); return 0; }
static int print_write(const char *path, const void *data, u64 offset, u64 len, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("write\t%llu\t%llu\t%s\n", (unsigned long long)offset, (unsigned long long)len, full_path); free(full_path); return 0; }
static int process_rename(const char *from, const char *to, void *user) { int ret; struct btrfs_receive *r = user; char *full_from = path_cat(r->full_subvol_path, from); char *full_to = path_cat(r->full_subvol_path, to); if (g_verbose >= 2) fprintf(stderr, "rename %s -> %s\n", from, to); ret = rename(full_from, full_to); if (ret < 0) { ret = -errno; fprintf(stderr, "ERROR: rename %s -> %s failed. %s\n", from, to, strerror(-ret)); } free(full_from); free(full_to); return ret; }
static int print_utimes(const char *path, struct timespec *at, struct timespec *mt, struct timespec *ct, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("utimes\t%s\n", full_path); free(full_path); return 0; }
static int print_clone(const char *path, u64 offset, u64 len, const u8 *clone_uuid, u64 clone_ctransid, const char *clone_path, u64 clone_offset, void *user) { struct recv_args *r = user; char *full_path = path_cat(r->full_subvol_path, path); printf("clone\t%s\t%s\n", full_path, clone_path); free(full_path); return 0; }
int main(int argc, char** argv) { struct dirent *dp; struct dirent **dps; const char *dir_path="/assets/sounds/"; DIR *dir = opendir(dir_path); if (dir) { while ((dp=readdir(dir)) != NULL) { char *tmp; tmp = path_cat(dir_path, dp->d_name); if (strcmp(".", dp->d_name) == 0 || strcmp("..", dp->d_name) == 0) { } else { FILE *fd = fopen(tmp, "rb"); fseek(fd, 0, SEEK_END); unsigned int len = ftell(fd); rewind(fd); void *buffer = (void *)malloc(sizeof(char) * len); fseek(fd, 0, SEEK_SET); size_t r = fread(buffer, 1, len, fd); if (r > 0) { m_Sounds.push_back(ModPlug_Load(buffer, len)); } free(buffer); } free(tmp); tmp=NULL; } closedir(dir); } // Set 16-bit stereo audio at 44.1Khz SDL_AudioSpec fmt; fmt.freq = 44100; fmt.format = AUDIO_S16; fmt.channels = 2; fmt.samples = (int)((1.0 / 35.0) * ((float)fmt.freq / (float)sizeof(short))); printf("%d\n", fmt.samples); fmt.callback = mixaudio; fmt.userdata = NULL; // Open the audio device and start playing sound! if (SDL_OpenAudio(&fmt, NULL) < 0) { printf("No audio: %s\n", SDL_GetError()); } else { SDL_PauseAudio(0); } throw 0; //crashes the main loop and allows the callbacks to proceed, kinda ugly return 0; }
static int print_subvol(const char *path, const u8 *uuid, u64 ctransid, void *user) { struct recv_args *r = user; char uuid_str[128]; r->full_subvol_path = path_cat(r->root_path, path); uuid_unparse(uuid, uuid_str); printf("subvol\t%s\t%llu\t%s\n", uuid_str, (unsigned long long)ctransid, r->full_subvol_path); return 0; }
// Try base/../pony_packages/path, and keep adding .. to look another level up // until we are looking in /pony_packages/path static const char* try_package_path(const char* base, const char* path) { char path1[FILENAME_MAX]; char path2[FILENAME_MAX]; path_cat(NULL, base, path1); do { path_cat(path1, "..", path2); if(pony_realpath(path2, path1) != path1) break; path_cat(path1, "pony_packages", path2); const char* result = try_path(path2, path); if(result != NULL) return result; } while(!is_root(path1)); return NULL; }
void pfx_cert_install_cb(void *data, Evas_Object *obj, void *event_info) { LOGD("pfx_cert_cb"); struct ug_data *ad = (struct ug_data *) data; Evas_Object *list = NULL; DIR *dir; struct dirent *dp; firstListElement = initList(); lastListElement = firstListElement; list = elm_list_add(ad->win_main); elm_list_mode_set(list, ELM_LIST_COMPRESS); dir = opendir(dir_path); if (dir == NULL) { LOGE("There's no such directory: %s", dir_path); return; //TODO What if there's no SD card? } LOGD("Scanning dir (%s) - looking for certs", dir_path); while ((dp = readdir(dir)) != NULL) { char *tmp; tmp = path_cat(dir_path, dp->d_name); char *dot = strrchr(dp->d_name, '.'); if(dot != NULL && strlen(dot)>3 && (strncmp(dot, ".pfx", 4) == 0 || strncmp(dot, ".PFX", 4) == 0 || strncmp(dot, ".p12", 4) == 0 || strncmp(dot, ".P12", 4) == 0)) { if (!(dp->d_type == DT_DIR)) { Elm_Object_Item * it; struct ListElement *current; current = addListElement(lastListElement, dp->d_name); lastListElement = current; it = elm_list_item_append(list, dp->d_name, NULL, NULL, install_pfx_button_cb, current); LOGD("elm list append = %s", current->name); } if (tmp) { free(tmp); tmp = NULL; } } } closedir(dir); elm_naviframe_item_push(ad->navi_bar, dgettext(PACKAGE, "CHOOSE_PFX_TO_INSTALL"), NULL, NULL, list, NULL); }
int main () { struct dirent *dp; // enter existing path to directory below const char *dir_path="testing/"; DIR *dir = opendir(dir_path); while ((dp=readdir(dir)) != NULL) { char *tmp; tmp = path_cat(dir_path, dp->d_name); printf("%s\n", tmp); free(tmp); tmp=NULL; } closedir(dir); return 0; }
static int process_subvol(const char *path, const u8 *uuid, u64 ctransid, void *user) { int ret; struct btrfs_receive *r = user; struct btrfs_ioctl_vol_args args_v1; char uuid_str[BTRFS_UUID_UNPARSED_SIZE]; ret = finish_subvol(r); if (ret < 0) goto out; r->cur_subvol = calloc(1, sizeof(*r->cur_subvol)); if (strlen(r->dest_dir_path) == 0) r->cur_subvol->path = strdup(path); else r->cur_subvol->path = path_cat(r->dest_dir_path, path); free(r->full_subvol_path); r->full_subvol_path = path_cat3(r->root_path, r->dest_dir_path, path); fprintf(stderr, "At subvol %s\n", path); memcpy(r->cur_subvol->received_uuid, uuid, BTRFS_UUID_SIZE); r->cur_subvol->stransid = ctransid; if (g_verbose) { uuid_unparse((u8*)r->cur_subvol->received_uuid, uuid_str); fprintf(stderr, "receiving subvol %s uuid=%s, stransid=%llu\n", path, uuid_str, r->cur_subvol->stransid); } memset(&args_v1, 0, sizeof(args_v1)); strncpy_null(args_v1.name, path); ret = ioctl(r->dest_dir_fd, BTRFS_IOC_SUBVOL_CREATE, &args_v1); if (ret < 0) { ret = -errno; fprintf(stderr, "ERROR: creating subvolume %s failed. " "%s\n", path, strerror(-ret)); goto out; } out: return ret; }
// Attempt to parse the source files in the specified directory and add them to // the given package AST // @return true on success, false on error static bool parse_files_in_dir(ast_t* package, const char* dir_path, pass_opt_t* options) { PONY_ERRNO err = 0; PONY_DIR* dir = pony_opendir(dir_path, &err); if(dir == NULL) { switch(err) { case EACCES: errorf(dir_path, "permission denied"); break; case ENOENT: errorf(dir_path, "does not exist"); break; case ENOTDIR: errorf(dir_path, "not a directory"); break; default: errorf(dir_path, "unknown error"); break; } return false; } PONY_DIRINFO dirent; PONY_DIRINFO* d; bool r = true; while(pony_dir_entry_next(dir, &dirent, &d) && (d != NULL)) { // Handle only files with the specified extension that don't begin with // a dot. This avoids including UNIX hidden files in a build. char* name = pony_dir_info_name(d); if(name[0] == '.') continue; const char* p = strrchr(name, '.'); if((p != NULL) && (strcmp(p, EXTENSION) == 0)) { char fullpath[FILENAME_MAX]; path_cat(dir_path, name, fullpath); r &= parse_source_file(package, fullpath, options); } } pony_closedir(dir); return r; }
// Check whether the directory specified by catting the given base and path // exists // @return The resulting directory path, which should not be deleted and is // valid indefinitely. NULL is directory cannot be found. static const char* try_path(const char* base, const char* path) { char composite[FILENAME_MAX]; char file[FILENAME_MAX]; path_cat(base, path, composite); if(pony_realpath(composite, file) != file) return NULL; struct stat s; int err = stat(file, &s); if((err != -1) && S_ISDIR(s.st_mode)) return stringtab(file); return NULL; }
static int process_mksock(const char *path, void *user) { int ret; struct btrfs_receive *r = user; char *full_path = path_cat(r->full_subvol_path, path); if (g_verbose >= 2) fprintf(stderr, "mksock %s\n", path); ret = mknod(full_path, 0600 | S_IFSOCK, 0); if (ret < 0) { ret = -errno; fprintf(stderr, "ERROR: mknod %s failed. %s\n", path, strerror(-ret)); } free(full_path); return ret; }
static int process_rmdir(const char *path, void *user) { int ret; struct btrfs_receive *r = user; char *full_path = path_cat(r->full_subvol_path, path); if (g_verbose >= 2) fprintf(stderr, "rmdir %s\n", path); ret = rmdir(full_path); if (ret < 0) { ret = -errno; fprintf(stderr, "ERROR: rmdir %s failed. %s\n", path, strerror(-ret)); } free(full_path); return ret; }