int download_check_link(const char * dst, const char * src, const char * md5, check_file_func_t cb) { char new_file[PATH_MAX] = {0}; snprintf(new_file, sizeof(new_file), "%s.%s", dst, timestamp2compact_str(get_now_tv()->tv_sec)); int ret = download_file(new_file, src, md5); if (0 != ret) { return ret; } if (NULL != cb) { ret = cb(new_file); if (0 != ret) { return ret; } } const char * new_file_name = get_filename(new_file); ret = link_file(new_file_name, dst); if (0 != ret) { return NODE_ERR_LINK_FILE; } return 0; }
void SvgGraph::read_links(const string& file_path) { ifstream link_file(file_path); strip_utf8header(link_file); string single_line; while (std::getline(link_file ,single_line)) { all_links.emplace_back(single_line); } }
static int hash_file(int dirfd, const char *filename) { STACK_OF(X509_INFO) *inf; X509_INFO *x; BIO *b; int i, count = 0; unsigned char digest[EVP_MAX_MD_SIZE]; b = BIO_openat(dirfd, filename); if (!b) return -1; inf = PEM_X509_INFO_read_bio(b, NULL, NULL, NULL); BIO_free(b); if (!inf) return -1; for(i = 0; i < sk_X509_INFO_num(inf); i++) { x = sk_X509_INFO_value(inf, i); if (x->x509) { X509_digest(x->x509, evpmd, digest, NULL); link_file(dirfd, filename, TYPE_CERT, X509_subject_name_hash(x->x509), digest); count++; } if (x->crl) { X509_CRL_digest(x->crl, evpmd, digest, NULL); link_file(dirfd, filename, TYPE_CRL, X509_NAME_hash(X509_CRL_get_issuer(x->crl)), digest); count++; } } sk_X509_INFO_pop_free(inf, X509_INFO_free); if (count == 0) { fprintf(stderr, "WARNING: %s does not contain a certificate or CRL: skipping\n", filename); } return count; }
int simple_copyfile(const char* input_file_path,const char* output_file_path) //执行相关拷贝动作 { int n; int filehand_src,filehand_dst; char buf[BUFFSIZE]; char lf[MAX_PATH_LENGTH]; struct stat info; file_status(input_file_path, &info); if(ga.need_interactive) { if(!interactivity_method(output_file_path)) { return true; } }else{ overwrite = O_EXCL; } if(ga.need_preserve == true) { if((filehand_dst = preserve_method(info,input_file_path,output_file_path)) == SUCCESS_LINK) return true; }else if(ga.need_no_deference == true){ if(ENUM_SYMLINK == it) { input_file_path = realpath(input_file_path,lf); link_file(input_file_path, output_file_path); return true; } }else if(ENUM_SYMLINK == it) { input_file_path = realpath(input_file_path,lf); filehand_dst = open_file(output_file_path,O_WRONLY|O_CREAT|overwrite, 0775); }else{ filehand_dst = open_file(output_file_path,O_WRONLY|O_CREAT|overwrite, 0775); } filehand_src = open_file(input_file_path,O_RDONLY); while((n = read_file(filehand_src,buf,BUFFSIZE,input_file_path)) > 0) write_file(filehand_dst,buf,n,output_file_path); close(filehand_src); close(filehand_dst); return true; }
int main(int argc, const char *argv[]) { if (strcmp(argv[1], "-d") == 0) { const char *from = argv[2]; const char *dir = argv[3]; copy_to_directory(from, dir); } else if (strcmp(argv[1], "-s") == 0) { const char *from = argv[2]; const char *to = argv[3]; link_file(from, to); } else { const char *from = argv[1]; const char *to = argv[2]; copy_file(from, to); } return 0; }
int main(int argc, char *argv[]) { int ch, oflags; char fname[FILENAME_MAX]; char *endp; quiet = 0; mode = ' '; while ((ch = getopt(argc, argv, "irwlpdqfh:")) != -1) { switch (ch) { case 'q': quiet = 1; break; case 'f': /* Legacy. Do nothing. */ break; case 'i': mode = 'i'; break; case 'h': volhdr_size = strtol(optarg, &endp, 0); if (*endp != '\0' || errno != 0) errx(1, "incorrect volume header size: %s", optarg); break; case 'r': mode = 'r'; break; case 'w': mode = 'w'; break; case 'l': mode = 'l'; break; case 'd': mode = 'd'; break; case 'p': mode = 'p'; break; default: usage(); } } argc -= optind; argv += optind; if (mode == 'r' || mode == 'w' || mode == 'l') { if (argc != 3) usage(); vfilename = argv[0]; ufilename = argv[1]; argc -= 2; argv += 2; } else if (mode == 'd') { if (argc != 2) usage(); vfilename = argv[0]; argc--; argv++; } else if (mode == 'p') { if (argc != 5) usage(); partno = strtol(argv[0], &endp, 0); if (*endp != '\0' || errno != 0 || partno < 0 || partno > SGI_SIZE_VOLDIR) errx(1, "invalid partition number: %s", argv[0]); partfirst = strtol(argv[1], &endp, 0); if (*endp != '\0' || errno != 0) errx(1, "invalid partition start: %s", argv[1]); partblocks = strtol(argv[2], &endp, 0); if (*endp != '\0' || errno != 0) errx(1, "invalid partition size: %s", argv[2]); parttype = strtol(argv[3], &endp, 0); if (*endp != '\0' || errno != 0) errx(1, "invalid partition type: %s", argv[3]); argc -= 4; argv += 4; } if (argc != 1) usage(); oflags = ((mode == 'i' || mode == 'w' || mode == 'l' || mode == 'd' || mode == 'p') ? O_RDWR : O_RDONLY); /* Open raw device. */ if ((fd = open(argv[0], oflags)) < 0) { snprintf(fname, sizeof(fname), "/dev/r%s%c", argv[0], 'a' + getrawpartition()); if ((fd = open(fname, oflags)) < 0) err(1, "open %s", fname); } /* Get disklabel for device. */ if (ioctl(fd, DIOCGDINFO, &lbl) == -1) err(1, "ioctl DIOCGDINFO"); /* Allocate a buffer that matches the device sector size. */ bufsize = lbl.d_secsize; if (bufsize < sizeof(struct sgilabel)) errx(1, "sector size is smaller than SGI volume header!\n"); if ((buf = malloc(bufsize)) == NULL) err(1, "failed to allocate buffer"); /* Read SGI volume header. */ if (read(fd, buf, bufsize) != bufsize) err(1, "read volhdr"); volhdr = (struct sgilabel *)buf; if (mode == 'i') { init_volhdr(); exit(0); } if (betoh32(volhdr->magic) != SGILABEL_MAGIC) errx(2, "no Volume Header found, magic=%x. Use -i first.", betoh32(volhdr->magic)); if (mode == 'r') read_file(); else if (mode == 'w') write_file(); else if (mode == 'l') link_file(); else if (mode == 'd') delete_file(); else if (mode == 'p') modify_partition(); else if (!quiet) display_vol(); exit (0); }