本文整理汇总了C++中copyfile函数的典型用法代码示例。如果您正苦于以下问题:C++ copyfile函数的具体用法?C++ copyfile怎么用?C++ copyfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了copyfile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: update_volume
static int update_volume(libubi_t libubi, int fdsw, struct img_type *img,
struct ubi_vol_info *vol)
{
long long bytes;
int fdout;
char node[64];
int err;
unsigned long offset = 0;
uint32_t checksum = 0;
char sbuf[128];
bytes = img->size;
if (!libubi) {
ERROR("Request to write into UBI, but no UBI on system");
return -1;
}
if (bytes > vol->rsvd_bytes) {
ERROR("\"%s\" (size %lld) will not fit volume \"%s\" (size %lld)",
img->fname, bytes, img->volname, vol->rsvd_bytes);
return -1;
}
snprintf(node, sizeof(node), "/dev/ubi%d_%d",
vol->dev_num,
vol->vol_id);
err = ubi_probe_node(libubi, node);
if (err == 1) {
ERROR("\"%s\" is an UBI device node, not an UBI volume node",
node);
return -1;
}
if (err < 0) {
if (errno == ENODEV)
ERROR("%s is not an UBI volume node", node);
else
ERROR("error while probing %s", node);
return -1;
}
fdout = open(node, O_RDWR);
if (fdout < 0) {
ERROR("cannot open UBI volume \"%s\"", node);
return -1;
}
err = ubi_update_start(libubi, fdout, bytes);
if (err) {
ERROR("cannot start volume \"%s\" update", node);
return -1;
}
snprintf(sbuf, sizeof(sbuf), "Installing image %s into volume %s(%s)",
img->fname, node, img->volname);
notify(RUN, RECOVERY_NO_ERROR, sbuf);
printf("Updating UBI : %s %lld %lu\n",
img->fname, img->size, offset);
if (copyfile(fdsw, fdout, img->size, (unsigned long *)&img->offset, 0,
img->compressed, &checksum) < 0) {
ERROR("Error copying extracted file");
err = -1;
}
close(fdout);
return err;
}
开发者ID:ruinned,项目名称:swupdate,代码行数:68,代码来源:ubivol_handler.c
示例2: remote_filereq
static void remote_filereq(int idx, char *from, char *file)
{
char *p = NULL, *what = NULL, *dir = NULL,
*s1 = NULL, *reject = NULL, *s = NULL;
FILE *fdb = NULL;
int i = 0;
filedb_entry *fdbe = NULL;
malloc_strcpy(what, file);
p = strrchr(what, '/');
if (p) {
*p = 0;
malloc_strcpy(dir, what);
strcpy(what, p + 1);
} else {
malloc_strcpy(dir, "");
}
fdb = filedb_open(dir, 0);
if (!fdb) {
reject = FILES_DIRDNE;
} else {
filedb_readtop(fdb, NULL);
fdbe = filedb_matchfile(fdb, ftell(fdb), what);
filedb_close(fdb);
if (!fdbe) {
reject = FILES_FILEDNE;
} else {
if ((!(fdbe->stat & FILE_SHARE)) ||
(fdbe->stat & (FILE_HIDDEN | FILE_DIR)))
reject = FILES_NOSHARE;
else {
s1 = nmalloc(strlen(dccdir) + strlen(dir) + strlen(what) + 2);
/* Copy to /tmp if needed */
sprintf(s1, "%s%s%s%s", dccdir, dir, dir[0] ? "/" : "", what);
if (copy_to_tmp) {
s = nmalloc(strlen(tempdir) + strlen(what) + 1);
sprintf(s, "%s%s", tempdir, what);
copyfile(s1, s);
} else
s = s1;
i = raw_dcc_send(s, "*remote", FILES_REMOTE, s);
if (i > 0) {
wipe_tmp_filename(s, -1);
reject = FILES_SENDERR;
}
if (s1 != s)
my_free(s);
my_free(s1);
}
free_fdbe(&fdbe);
}
}
s1 = nmalloc(strlen(botnetnick) + strlen(dir) + strlen(what) + 3);
simple_sprintf(s1, "%s:%s/%s", botnetnick, dir, what);
if (reject) {
botnet_send_filereject(idx, s1, from, reject);
my_free(s1);
my_free(what);
my_free(dir);
return;
}
/* Grab info from dcc struct and bounce real request across net */
i = dcc_total - 1;
s = nmalloc(40); /* Enough? */
simple_sprintf(s, "%d %u %d", iptolong(getmyip()), dcc[i].port,
dcc[i].u.xfer->length);
botnet_send_filesend(idx, s1, from, s);
putlog(LOG_FILES, "*", FILES_REMOTEREQ, dir, dir[0] ? "/" : "", what);
my_free(s1);
my_free(s);
my_free(what);
my_free(dir);
}
开发者ID:Protospace,项目名称:protobot,代码行数:73,代码来源:filedb3.c
示例3: setup_mac_metadata
/*
* The Mac OS "copyfile()" API copies the extended metadata for a
* file into a separate file in AppleDouble format (see RFC 1740).
*
* Mac OS tar and cpio implementations store this extended
* metadata as a separate entry just before the regular entry
* with a "._" prefix added to the filename.
*
* Note that this is currently done unconditionally; the tar program has
* an option to discard this information before the archive is written.
*
* TODO: If there's a failure, report it and return ARCHIVE_WARN.
*/
static int
setup_mac_metadata(struct archive_read_disk *a,
struct archive_entry *entry, int *fd)
{
int tempfd = -1;
int copyfile_flags = COPYFILE_NOFOLLOW | COPYFILE_ACL | COPYFILE_XATTR;
struct stat copyfile_stat;
int ret = ARCHIVE_OK;
void *buff = NULL;
int have_attrs;
const char *name, *tempdir;
struct archive_string tempfile;
(void)fd; /* UNUSED */
name = archive_entry_sourcepath(entry);
if (name == NULL)
name = archive_entry_pathname(entry);
if (name == NULL) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"Can't open file to read extended attributes: No name");
return (ARCHIVE_WARN);
}
if (a->tree != NULL) {
if (a->tree_enter_working_dir(a->tree) != 0) {
archive_set_error(&a->archive, errno,
"Couldn't change dir");
return (ARCHIVE_FAILED);
}
}
/* Short-circuit if there's nothing to do. */
have_attrs = copyfile(name, NULL, 0, copyfile_flags | COPYFILE_CHECK);
if (have_attrs == -1) {
archive_set_error(&a->archive, errno,
"Could not check extended attributes");
return (ARCHIVE_WARN);
}
if (have_attrs == 0)
return (ARCHIVE_OK);
tempdir = NULL;
if (issetugid() == 0)
tempdir = getenv("TMPDIR");
if (tempdir == NULL)
tempdir = _PATH_TMP;
archive_string_init(&tempfile);
archive_strcpy(&tempfile, tempdir);
archive_strcat(&tempfile, "tar.md.XXXXXX");
tempfd = mkstemp(tempfile.s);
if (tempfd < 0) {
archive_set_error(&a->archive, errno,
"Could not open extended attribute file");
ret = ARCHIVE_WARN;
goto cleanup;
}
__archive_ensure_cloexec_flag(tempfd);
/* XXX I wish copyfile() could pack directly to a memory
* buffer; that would avoid the temp file here. For that
* matter, it would be nice if fcopyfile() actually worked,
* that would reduce the many open/close races here. */
if (copyfile(name, tempfile.s, 0, copyfile_flags | COPYFILE_PACK)) {
archive_set_error(&a->archive, errno,
"Could not pack extended attributes");
ret = ARCHIVE_WARN;
goto cleanup;
}
if (fstat(tempfd, ©file_stat)) {
archive_set_error(&a->archive, errno,
"Could not check size of extended attributes");
ret = ARCHIVE_WARN;
goto cleanup;
}
buff = malloc(copyfile_stat.st_size);
if (buff == NULL) {
archive_set_error(&a->archive, errno,
"Could not allocate memory for extended attributes");
ret = ARCHIVE_WARN;
goto cleanup;
}
if (copyfile_stat.st_size != read(tempfd, buff, copyfile_stat.st_size)) {
archive_set_error(&a->archive, errno,
"Could not read extended attributes into memory");
ret = ARCHIVE_WARN;
goto cleanup;
}
//.........这里部分代码省略.........
开发者ID:AAZemlyanukhin,项目名称:freebsd,代码行数:101,代码来源:archive_read_disk_entry_from_file.c
示例4: load_friends
/* Because this function is called at the beginning, and if it returns -1
* the program will exit soon. So there is no need to free resource here.
*/
static int load_friends() {
int distance = 0, line = 0;
FILE *fp;
char buf[EACH_MSG_LEN*2], curr_user[IDLEN+1], tar_user[IDLEN+1];
char *ptr;
UserNode *punode_op = NULL, *punode_ta = NULL;
Relationship *pr;
if(!file_exist(MY_BBS_HOME "/friends.dump")) //可运行时dump
return 0;
fp = fopen(MY_BBS_HOME "/friends.dump", "r");
if(fp == NULL)
return -1;
curr_user[0] = '\0';
while(fgets(buf, sizeof(buf)-1, fp)) {
if(*buf == '\n' || *buf == '\0') //空行,文件结束
break;
if(*buf == '#') { //新的user
if((ptr = strchr(buf, '\n')) != NULL)
*ptr = '\0';
strncpy(curr_user, buf+1, sizeof(curr_user));
punode_op = get_afriend(curr_user);
if(punode_op == NULL)
return -1;
} else {
if(punode_op == NULL) //bad file-format
return -1;
ptr = strchr(buf, ' ');
if(ptr == NULL) //bad file-format
return -1;
*ptr = '\0';
strncpy(tar_user, buf, sizeof(tar_user));
distance = atoi(ptr+1);
punode_ta = get_afriend(tar_user);
if(punode_ta == NULL)
return -1;
pr = calloc(1, sizeof(Relationship));
if(pr == NULL)
return -1;
pr->ptr = punode_ta;
pr->distance = distance;
if(insert_node(punode_op->to, pr) == -1)
return -1;
pr = calloc(1, sizeof(Relationship));
if(pr == NULL)
return -1;
pr->ptr = punode_op;
pr->distance = distance;
if(insert_node(punode_ta->from, pr) == -1)
return -1;
}
line++;
}
fclose(fp);
if(line > 0)
copyfile(MY_BBS_HOME "/friends.dump", MY_BBS_HOME "/friends.dump.good");
return 0;
}
开发者ID:long5313828,项目名称:ythtbbs,代码行数:67,代码来源:friends.c
示例5: tb_file_copy
tb_bool_t tb_file_copy(tb_char_t const* path, tb_char_t const* dest)
{
// check
tb_assert_and_check_return_val(path && dest, tb_false);
#ifdef TB_CONFIG_POSIX_HAVE_COPYFILE
// the full path
tb_char_t full0[TB_PATH_MAXN];
path = tb_path_absolute(path, full0, TB_PATH_MAXN);
tb_assert_and_check_return_val(path, tb_false);
// the dest path
tb_char_t full1[TB_PATH_MAXN];
dest = tb_path_absolute(dest, full1, TB_PATH_MAXN);
tb_assert_and_check_return_val(dest, tb_false);
// attempt to copy it directly
if (!copyfile(path, dest, 0, COPYFILE_ALL)) return tb_true;
else
{
// attempt to copy it again after creating directory
tb_char_t dir[TB_PATH_MAXN];
if (tb_directory_create(tb_path_directory(dest, dir, sizeof(dir))))
return !copyfile(path, dest, 0, COPYFILE_ALL);
}
// failed
return tb_false;
#else
tb_int_t ifd = -1;
tb_int_t ofd = -1;
tb_bool_t ok = tb_false;
do
{
// get the absolute source path
tb_char_t data[8192];
path = tb_path_absolute(path, data, sizeof(data));
tb_assert_and_check_break(path);
// get stat.st_mode first
#ifdef TB_CONFIG_POSIX_HAVE_STAT64
struct stat64 st = {0};
if (stat64(path, &st)) break;
#else
struct stat st = {0};
if (stat(path, &st)) break;
#endif
// open source file
ifd = open(path, O_RDONLY);
tb_check_break(ifd >= 0);
// get the absolute source path
dest = tb_path_absolute(dest, data, sizeof(data));
tb_assert_and_check_break(dest);
// open destinate file and copy file mode
ofd = open(dest, O_RDWR | O_CREAT | O_TRUNC, st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));
if (ofd < 0)
{
// attempt to open it again after creating directory
tb_char_t dir[TB_PATH_MAXN];
if (tb_directory_create(tb_path_directory(dest, dir, sizeof(dir))))
ofd = open(dest, O_RDWR | O_CREAT | O_TRUNC, st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));
}
tb_check_break(ofd >= 0);
// get file size
tb_hize_t size = tb_file_size(tb_fd2file(ifd));
// init write size
tb_hize_t writ = 0;
// attempt to copy file using `sendfile`
#ifdef TB_CONFIG_POSIX_HAVE_SENDFILE
while (writ < size)
{
off_t seek = writ;
tb_hong_t real = sendfile(ofd, ifd, &seek, (size_t)(size - writ));
if (real > 0) writ += real;
else break;
}
/* attempt to copy file directly if sendfile failed
*
* sendfile() supports regular file only after "since Linux 2.6.33".
*/
if (writ != size)
{
lseek(ifd, 0, SEEK_SET);
lseek(ofd, 0, SEEK_SET);
}
else
{
ok = tb_true;
break;
}
#endif
//.........这里部分代码省略.........
开发者ID:ljx0305,项目名称:tbox,代码行数:101,代码来源:file.c
示例6: main
//.........这里部分代码省略.........
}
break;
case 'H':
strncpy(hostname, optarg, MAXHOSTNAMELEN);
break;
case 'P':
username = optarg;
break;
default:
case '?':
fprintf(stderr, "unknown option %c\n", c);
usgflg++;
}
if (argc < 2) usgflg++;
if (optind < argc) {
desthostname = argv[optind++];
} else
usgflg++;
if (usgflg) {
fprintf(stderr, "usage: to send a job - %s -d printer -H hostname -P username [-s seqno] [-t[cdfgklnoprtvz]] desthost [filename]\n", argv[0]);
fprintf(stderr, " to check status - %s -d printer -q desthost\n", argv[0]);
fprintf(stderr, " to kill a job - %s -d printer -P username -k jobname desthost\n", argv[0]);
exit(1);
}
/* make sure the file to send is here and ready
* otherwise the TCP connection times out.
*/
if (!statflag && !killflag) {
if (optind < argc) {
inputname = argv[optind++];
debug("open("); debug(inputname); debug(")\n");
inputfd = open(inputname, O_RDONLY);
if (inputfd < 0) {
fprintf(stderr, "open(%s) failed\n", inputname);
exit(1);
}
} else {
inputname = "stdin";
tmpnam(tmpfilename);
debug("using stdin\n");
if ((inputfd = open(tmpfilename, O_RDWR|O_CREAT, 0600)) < 0) {
fprintf(stderr, "open(%s) failed\n", tmpfilename);
exit(1);
}
atexit(cleanup);
debug("copy input to temp file ");
debug(tmpfilename);
debug("\n");
if (!copyfile(0, inputfd, 0L)) {
fprintf(stderr, "failed to copy file to temporary file\n");
exit(1);
}
if (lseek(inputfd, 0L, 0) < 0) {
fprintf(stderr, "failed to seek back to the beginning of the temporary file\n");
exit(1);
}
}
}
sprintf(strbuf, "%s", netmkaddr(desthostname, "tcp", "printer"));
fprintf(stderr, "connecting to %s\n", strbuf);
for (sendport=721; sendport<=731; sendport++) {
sprintf(portstr, "%3.3d", sendport);
fprintf(stderr, " trying from port %s...", portstr);
debug(" dial("); debug(strbuf); debug(", "); debug(portstr); debug(", 0, 0) ...");
printerfd = dial(strbuf, portstr, 0, 0);
if (printerfd >= 0) {
fprintf(stderr, "connected\n");
break;
}
fprintf(stderr, "failed\n");
sleep(REDIALTIMEOUT);
}
if (printerfd < 0) {
fprintf(stderr, "Cannot open a valid port!\n");
fprintf(stderr, "- All source ports [721-731] may be busy.\n");
fprintf(stderr, "- Is recipient ready and online?\n");
fprintf(stderr, "- If all else fails, cycle the power!\n");
exit(1);
}
/* hostname[8] = '\0'; */
#ifndef PLAN9
if (gethostname(hostname, sizeof(hostname)) < 0) {
perror("gethostname");
exit(1);
}
#endif
/* if ((hnend = strchr(hostname, '.')) != NULL)
*hnend = '\0';
*/
if (statflag) {
checkqueue(printerfd);
} else if (killflag) {
killjob(printerfd);
} else {
sendjob(inputfd, printerfd);
}
exit(0);
}
开发者ID:AustenConrad,项目名称:plan-9,代码行数:101,代码来源:lpdsend.c
示例7: main
int main (int argc, char **argv)
{
int i;
int fd[argc];
int outfd = 1;
int ix;
/* Process Option Arguments */
ix = 1;
if (argc > ix && argv[ix][0] == '-' && argv[ix][1] == 'd') {
debug = 1;
ix++;
}
if (argc > ix && argv[ix][0] == '-')
{
if (argv[ix][1] == 'o' && argv[ix][2] == 0 && argc > 2)
{
/* Open the output file. */
outfd = open (argv[ix+1], O_WRONLY|O_CREAT|O_TRUNC,
0777);
if (outfd < 0)
{
write (2, "Can not open output file ", 25);
write (2, argv[ix+1], strlen(argv[ix+1]));
write (2, ".\n", 2);
exit (1);
}
/* Adjust argv/argc to ignore -o option. */
ix += 2;
}
else if (strcmp(argv[ix], "-f") == 0)
{
debug = 1;
}
else
{
write (2, "Usage: ", 7);
write (2, argv[0], strlen(argv[0]));
write (2, " [-d] [-o file] [files ...]\n", 28);
exit (1);
}
}
if (argc == 1)
{ /* Read from standard in! */
copyfile (0, outfd);
}
else
{ /* For each argument, open the file, copy it to outfd, close it. */
for (i = ix; i < argc; i++)
{
fd[i] = open (argv[i], O_RDONLY, 0);
if (fd[i] < 0)
{
write (2, "Can not open file ", 18);
write (2, argv[i], strlen(argv[i]));
write (2, ".\n", 2);
exit (1);
}
copyfile (fd[i], outfd);
}
for (i = ix; i < argc; i++)
close (fd[i]);
}
/* Done successfully */
close(outfd);
exit (0);
}
开发者ID:janaknm,项目名称:school,代码行数:70,代码来源:cat.c
示例8: _inotify_event_handler
static void _inotify_event_handler(struct inotify_event *event)
{
/* Perform event dependent handler routines */
/* The mask is the magic that tells us what file operation occurred */
if(strstr(event->name,UNIX_Z)==0)
{
/*File was closed */
if(event->mask & IN_CLOSE_WRITE)
{
#ifdef DEBUG
printf("wd:%d",event->wd);
printf("IN_CLOSE_WRITE\n");
printf("event->name: %s\n", event->name);
#endif
char command[COMMAND_SIZE]={0};
FILE *pf;
//get the command to compress the file with unix.z
if(event->wd==1)
sprintf(command,"compress -f %s%s",uploadPath->BDLocalPathPrefix,event->name);
else
sprintf(command,"compress -f %s%s",uploadPath->GNSSLocalPathPrefix,event->name);
//execute the command of compression
if((pf=popen(command,"r"))==NULL)
{
//compression failed
#ifdef _DEBUG
perror("压缩失败");
#endif
}
pclose(pf);
up_delay();
}
/* File was deleted means the compression is over*/
if(event->mask & IN_DELETE)
{
#ifdef DEBUG
printf("IN_DELETE\n");
printf("event->name: %s\n", event->name);
#endif
int type = event-> wd;
char name[STD_FILENAME_SIZE]="0";
strcpy(name,event->name);
if(nodeIsExist(name,type)==1)
{
char * dir;
UploadNode *p0;
p0=(UploadNode *)malloc(sizeof(UploadNode));
int len1 = strlen(name)+strlen(UNIX_Z)+1;
p0->filename=(char *)malloc(len1);
memset(p0->filename,0, len1);
sprintf(p0->filename,"%s%s",name,UNIX_Z);
printf("filename:%s\n",p0->filename);
//move the file to the backup folder
dir = (char *)malloc(10);
memset(dir,0,10);
//move the file to the backup folder
copyfile(p0->filename,type,dir);
//BEIDOU
if(type==1)
{
int len2=strlen(uploadPath->BDLocalPathPrefix)+1;
p0->analysisCenterPath=(char *)malloc(len2);
memset(p0->analysisCenterPath,0, len2);
strcpy(p0->analysisCenterPath,uploadPath->BDLocalPathPrefix);
int len3 = strlen(uploadPath->BDRemotePathPrefix)+strlen(dir)+strlen(PATH_SUFFIX)+1;
p0->productCenterPath=(char *)malloc(len3);
memset(p0->productCenterPath,0, len3);
sprintf(p0->productCenterPath,"%s%s%s",uploadPath->BDRemotePathPrefix,dir,PATH_SUFFIX);
}
//GNSS
else
{
int len2=strlen(uploadPath->GNSSLocalPathPrefix)+1;
p0->analysisCenterPath=(char *)malloc(len2);
memset(p0->analysisCenterPath,0, len2);
strcpy(p0->analysisCenterPath,uploadPath->GNSSLocalPathPrefix);
int len3 = strlen(uploadPath->GNSSRemotePathPrefix)+strlen(dir)+strlen(PATH_SUFFIX)+1;
p0->productCenterPath=(char *)malloc(len3);
memset(p0->productCenterPath,0, len3);
sprintf(p0->productCenterPath,"%s%s%s",uploadPath->GNSSRemotePathPrefix,dir,PATH_SUFFIX);
}
p0->state=UPLOAD_FILE_EXIST;
p0->type = type;
p0->server=fs->next;
#ifdef DEBUG
printf("filename:%s\n",p0->filename);
printf("传入:%s\n",p0->filename);
log_checktask(p0->filename,"文件创建");
//.........这里部分代码省略.........
开发者ID:jungsagacity,项目名称:ftp,代码行数:101,代码来源:upload.c
示例9: makeSendFile
/* -------------------------------------------------------------------- */
static void makeSendFile(void)
{
char line[100], line2[100];
label troo;
label fn;
FILE *file;
int i = 0, rm;
if ((file = fopen(roomreqin, "rb")) == NULL)
{
perror("Error opening roomreq.in");
}
doccr();
cPrintf(" Fetching:");
doccr();
GetStr(file, troo, LABELSIZE);
while(strlen(troo) && !feof(file))
{
if ((rm = roomExists(troo)) != ERROR)
{
if (nodecanseeroom(node.ndname, rm))
{
sprintf(fn, "room.%d", i);
cPrintf(" %-20s ", troo);
if( !((i+1) % 3) ) doccr();
NewRoom(rm, fn);
}
else
{
doccr();
cPrintf(" No access to %s room.", troo);
doccr();
amPrintf(" '%s' room not available to remote.\n", troo);
netError = TRUE;
}
}
else
{
doccr();
cPrintf(" No %s room on system.", troo);
doccr();
amPrintf(" '%s' room not found for remote.\n", troo);
netError = TRUE;
}
i++;
GetStr(file, troo, LABELSIZE);
}
doccr();
fclose(file);
unlink(roomreqin);
cPrintf(" Copying mail file.");
doccr();
sprintf(line, "%s\\%s", cfg.transpath, node.ndmailtmp);
sprintf(line2, "%s\\mesg.tmp", cfg.temppath);
if ((file = fopen(line2, "wb")) != NULL)
{
fclose(file);
}
copyfile(line, line2);
cPrintf(" Compressing message files.");
doccr();
/*
* Zip them up
*/
sformat(line, node.zip, "df", roomdataout, "mesg.tmp room.*");
apsystem(line);
/*
* Remove them.
*/
ambigUnlink("room.*", FALSE);
unlink("mesg.tmp");
}
开发者ID:dylancarlson,项目名称:atlas,代码行数:81,代码来源:NETDC15.C
示例10: yymain
/*
* Yymain initializes each of the utility
* clusters and then starts the processing
* by calling yyparse.
*/
yymain()
{
#ifdef OBJ
/*
* initialize symbol table temp files
*/
startnlfile();
#endif
/*
* Initialize the scanner
*/
#ifdef PXP
if (bracket == 0) {
#endif
if (getline() == -1) {
Perror(filename, "No lines in file");
pexit(NOSTART);
}
#ifdef PXP
} else
yyline = 0;
#endif
#ifdef PI
# ifdef OBJ
magic();
# endif OBJ
#endif
line = 1;
errpfx = 'E';
/*
* Initialize the clusters
*
initstring();
*/
inithash();
inittree();
#ifdef PI
initnl();
#endif
/*
* Process the input
*/
yyparse();
#ifdef PI
# ifdef OBJ
/*
* save outermost block of namelist
*/
savenl(NLNIL);
magic2();
# endif OBJ
# ifdef DEBUG
dumpnl(NLNIL);
# endif
#endif
#ifdef PXP
prttab();
if (onefile) {
extern int outcol;
if (outcol)
pchr('\n');
flush();
if (eflg) {
writef(2, "File not rewritten because of errors\n");
pexit(ERRS);
}
(void) signal(SIGHUP, SIG_IGN);
(void) signal(SIGINT, SIG_IGN);
copyfile();
}
#endif
pexit(eflg ? ERRS : AOK);
}
开发者ID:ShanghaiTimes,项目名称:original-bsd,代码行数:85,代码来源:yymain.c
示例11: main
//.........这里部分代码省略.........
end_cmd()
begin_cmd("8bit256", 4)
repeat = (unsigned int) atoi(argv[3]);
_8bit256(argv[2], repeat);
end_cmd()
begin_cmd("eng2arab", 4)
eng2arab(argv[2], argv[3]);
end_cmd()
begin_cmd("arab2eng", 4)
arab2eng(argv[2], argv[3]);
end_cmd()
begin_cmd("e2ahtml", 4)
e2ahtml(argv[2], argv[3]);
end_cmd()
begin_cmd("freverse", 4)
freverse(argv[2], argv[3]);
end_cmd()
begin_cmd("repcat", 4)
repeat = (unsigned int) atoi(argv[3]);
repcat(argv[2], repeat);
end_cmd()
begin_cmd("repcatpp", 4)
repeat = (unsigned int) atoi(argv[3]);
repcatpp(argv[2], repeat);
end_cmd()
begin_cmd("copyfile", 4)
copyfile(argv[2], argv[3]);
end_cmd()
begin_cmd("qpatch", 4)
qpatch(argv[2], argv[3]);
end_cmd()
begin_cmd("flipcopy", 4)
flipcopy(argv[2], argv[3]);
end_cmd()
begin_cmd("fillfile", 4)
fillfile(argv[2], argv[3][0]);
end_cmd()
begin_cmd("bin2text", 4)
bin2text(argv[2], argv[3]);
end_cmd()
begin_cmd("bin2hexi", 4)
bin2hexi(argv[2], argv[3]);
end_cmd()
begin_cmd("rndbfile", 4)
rndbfile(argv[2], strtoul(argv[3], NULL, 0));
end_cmd()
begin_cmd("rndtfile", 4)
rndtfile(argv[2], strtoul(argv[3], NULL, 0));
end_cmd()
begin_cmd("skipcat", 4)
开发者ID:najitool,项目名称:najitool-libnaji-latest-code,代码行数:67,代码来源:najitool.c
示例12: main
//.........这里部分代码省略.........
#endif
tdlen = strlen(todir);
xchdir(cwd);
tdlen = strlen(todir);
uid = owner ? touid(owner) : (uid_t)(-1);
gid = group ? togid(group) : (gid_t)(-1);
while (--argc > 0) {
name = *argv++;
len = strlen(name);
base = xbasename(name);
bnlen = strlen(base);
toname = xmalloc((unsigned int)(tdlen + 1 + bnlen + 1));
sprintf(toname, "%s%s%s", todir, _DIRECTORY_SEPARATOR, base);
exists = (lstat(toname, &tosb) == 0);
if (dodir) {
/* -d means create a directory, always */
if (exists && !S_ISDIR(tosb.st_mode)) {
(void) unlink(toname);
exists = 0;
}
if (!exists && mkdir(toname, mode) < 0)
fail("cannot make directory %s", toname);
if ((owner || group) && chown(toname, uid, gid) < 0)
fail("cannot change owner of %s", toname);
} else if (dolink) {
if (access(name, R_OK) != 0) {
fail("cannot access %s", name);
}
if (*name == '/') {
/* source is absolute pathname, link to it directly */
linkname = 0;
} else {
if (linkprefix) {
/* -L implies -l and prefixes names with a $cwd arg. */
len += lplen + 1;
linkname = xmalloc((unsigned int)(len + 1));
sprintf(linkname, "%s/%s", linkprefix, name);
} else if (dorelsymlink) {
/* Symlink the relative path from todir to source name. */
linkname = xmalloc(PATH_MAX);
if (*todir == '/') {
/* todir is absolute: skip over common prefix. */
lplen = relatepaths(todir, cwd, linkname);
strcpy(linkname + lplen, name);
} else {
/* todir is named by a relative path: reverse it. */
reversepath(todir, name, len, linkname);
xchdir(cwd);
}
len = strlen(linkname);
}
name = linkname;
}
/* Check for a pre-existing symlink with identical content. */
if ((exists && (!S_ISLNK(tosb.st_mode) ||
readlink(toname, buf, sizeof buf) != len ||
strncmp(buf, name, (unsigned int)len) != 0)) ||
((stat(name, &fromsb) == 0) &&
(fromsb.st_mtime > tosb.st_mtime))) {
(void) (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname);
exists = 0;
}
if (!exists && symlink(name, toname) < 0)
fail("cannot make symbolic link %s", toname);
#ifdef HAVE_LCHOWN
if ((owner || group) && lchown(toname, uid, gid) < 0)
fail("cannot change owner of %s", toname);
#endif
if (linkname) {
free(linkname);
linkname = 0;
}
} else {
/* Copy from name to toname, which might be the same file. */
if( stat(name, &sb) == 0 && S_IFDIR & sb.st_mode )
{
/* then is directory: must explicitly create destination dir */
/* and manually copy files over */
copydir( name, todir, mode, group, owner, dotimes, uid, gid );
}
else
{
copyfile(name, toname, mode, group, owner, dotimes, uid, gid);
}
}
free(toname);
}
free(cwd);
free(todir);
return 0;
}
开发者ID:georgi,项目名称:jsmad,代码行数:101,代码来源:nsinstall.c
示例13: create_sliced_system
void create_sliced_system(boost::filesystem::path input_file, boost::filesystem::path output_file,
vec_mp * linears, int num_to_add,
const WitnessSet & W)
{
#ifdef functionentry_output
std::cout << "create_sliced_system" << std::endl;
#endif
if (W.num_var_names()==0) {
std::cout << "trying to create a sliced system, but witness set does not have the variable names." << std::endl;
deliberate_segfault();
}
int *declarations = NULL;
partition_parse(&declarations, input_file, "func_input", "config", 0); // the 0 means not self conjugate.
free(declarations);
FILE *OUT = safe_fopen_write(output_file);
FILE *IN = safe_fopen_read("func_input");
fprintf(OUT,"INPUT\n\n");
copyfile(IN,OUT);
fclose(IN);
std::vector< int > indicators;
for (int ii=0; ii<num_to_add; ii++) {
indicators.push_back(rand());
}
for (int ii=0; ii<num_to_add; ii++) {
std::stringstream linname;
linname << "supp_lin_" << indicators[ii];
write_vector_as_constants(linears[ii], linname.str(), OUT);
linname.clear(); linname.str("");
}
for (int ii=0; ii<num_to_add; ii++) {
fprintf(OUT,"function supp_lin_%d;\n",indicators[ii]);
}
for (int ii=0; ii<num_to_add; ii++) {
fprintf(OUT,"supp_lin_%d = supp_lin_%d_1",indicators[ii],indicators[ii]);
for (int jj=1; jj<W.num_variables(); jj++) {
fprintf(OUT," + %s*supp_lin_%d_%d",W.name(jj).c_str(), indicators[ii],jj+1);
}
fprintf(OUT, ";\n\n");
}
fprintf(OUT,"END;\n\n\n\n");
for (unsigned int ii=0; ii<W.num_patches(); ii++) {
std::stringstream linname;
linname << "patch_" << ii;
write_vector_as_constants(W.patch(ii), linname.str(), OUT);
linname.clear(); linname.str("");
}
fclose(OUT);
}
开发者ID:esudkamp,项目名称:bertini_real,代码行数:69,代码来源:slicing.cpp
示例14: uv__fs_copyfile
static ssize_t uv__fs_copyfile(uv_fs_t* req) {
#if defined(__APPLE__) && !TARGET_OS_IPHONE
/* On macOS, use the native copyfile(3). */
copyfile_flags_t flags;
flags = COPYFILE_ALL;
if (req->flags & UV_FS_COPYFILE_EXCL)
flags |= COPYFILE_EXCL;
return copyfile(req->path, req->new_path, NULL, flags);
#else
uv_fs_t fs_req;
uv_file srcfd;
uv_file dstfd;
struct stat statsbuf;
int dst_flags;
int result;
int err;
size_t bytes_to_send;
int64_t in_offset;
dstfd = -1;
err = 0;
/* Open the source file. */
srcfd = uv_fs_open(NULL, &fs_req, req->path, O_RDONLY, 0, NULL);
uv_fs_req_cleanup(&fs_req);
if (srcfd < 0)
return srcfd;
/* Get the source file's mode. */
if (fstat(srcfd, &statsbuf)) {
err = -errno;
goto out;
}
dst_flags = O_WRONLY | O_CREAT | O_TRUNC;
if (req->flags & UV_FS_COPYFILE_EXCL)
dst_flags |= O_EXCL;
/* Open the destination file. */
dstfd = uv_fs_open(NULL,
&fs_req,
req->new_path,
dst_flags,
statsbuf.st_mode,
NULL);
uv_fs_req_cleanup(&fs_req);
if (dstfd < 0) {
err = dstfd;
goto out;
}
if (fchmod(dstfd, statsbuf.st_mode) == -1) {
err = -errno;
goto out;
}
bytes_to_send = statsbuf.st_size;
in_offset = 0;
while (bytes_to_send != 0) {
err = uv_fs_sendfile(NULL,
&fs_req,
dstfd,
srcfd,
in_offset,
bytes_to_send,
NULL);
uv_fs_req_cleanup(&fs_req);
if (err < 0)
break;
bytes_to_send -= fs_req.result;
in_offset += fs_req.result;
}
out:
if (err < 0)
result = err;
else
result = 0;
/* Close the source file. */
err = uv__close_nocheckstdio(srcfd);
/* Don't overwrite any existing errors. */
if (err != 0 && result == 0)
result = err;
/* Close the destination file if it is open. */
if (dstfd >= 0) {
err = uv__close_nocheckstdio(dstfd);
/* Don't overwrite any existing errors. */
if (err != 0 && result == 0)
result = err;
//.........这里部分代码省略.........
开发者ID:Mikhaska,项目名称:node,代码行数:101,代码来源:fs.c
示例15: dochallenge
void dochallenge() {
string inpfile = CONFIG->GetTmpfile_path() + tmpnam();
retbott.Settype(CHALLENGE_REPORT);
datagen = NULL;
retbott.Setcha_id(bott->Getcha_id());
if (set_data(inpfile)) {
//failtogen
retbott.Setcha_result("Challenge Error");
retbott.Setcha_detail("Generator Failed: " + datagen->Getresult());
if (datagen != NULL) delete datagen;
} else {
string check_result_filename = CONFIG->GetTmpfile_path() + tmpnam();
int check_stat = check_data(bott->Getpid(), inpfile, check_result_filename);
if (check_stat == 1) {
retbott.Setcha_result("Challenge Error");
retbott.Setcha_detail("Data Check Failed: " + checker->Getresult() +
"\nChecker Output Detail:\n--------------------------\n" +
Loadallfromfile(check_result_filename) +
"\n--------------------------\nInvalid Data!!");
} else if (check_stat == -1) {
retbott.Setcha_result("Challenge Error");
retbott.Setcha_detail("No Config File For Problem: " +
Inttostring(bott->Getpid()));
} else {
stdprogram = new Program;
int stdres = run_program(stdprogram, inpfile,
Loadallfromfile(problem->Getsolution_filename()),
problem->Getsolution_language());
while (stdprogram->Getresult() == "Compile Error") {
stdprogram->Setcompiled(false);
stdprogram->Run();
if (stdprogram->Getresult() != "Normal") stdres = 1;
else stdres = 0;
}
usrprogram = new Program;
int usrres = run_program(usrprogram, inpfile, bott->Getsrc(),
bott->Getlanguage());
while (usrprogram->Getresult() == "Compile Error") {
usrprogram->Setcompiled(false);
usrprogram->Run();
if (usrprogram->Getresult() != "Normal") usrres = 1;
else usrres = 0;
}
if (stdres != 0) {
retbott.Setcha_result("Challenge Error");
retbott.Setcha_detail(
"Standard Program Failed: " + stdprogram->Getresult());
} else if (usrres != 0) {
retbott.Setcha_result("Challenge Success");
string newf = "cha_" + tmpnam();
copyfile(
stdprogram->Getin_filename(),
"testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".in");
copyfile(
stdprogram->Getout_filename(),
"testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".out");
retbott.Setcha_detail("Standard: " + stdprogram->Getresult() +
" User: " + usrprogram->Getresult());
} else {
cmp = new Comparator;
cmp->Setin_filename(inpfile);
cmp->Setout_filename(usrprogram->Getout_filename());
cmp->Setstdout_filename(stdprogram->Getout_filename());
cmp->Setsrc_filename(usrprogram->Getsrc_filename());
cmp->Setisspj(bott->Getspj());
cmp->Setpid(bott->Getpid());
int cres = cmp->Compare();
if (cres == AC_STATUS) {
retbott.Setcha_result("Challenge Failed");
retbott.Setcha_detail("Same Result.");
} else if (cres == PE_STATUS) {
retbott.Setcha_result("Challenge Success");
retbott.Setcha_detail(
"Presentation Error.\nComparator Output Detail:"
"\n--------------------------\n" + cmp->Getdetail() +
"\n--------------------------");
string newf = "cha_" + tmpnam();
copyfile(
stdprogram->Getin_filename(),
"testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".in");
copyfile(
stdprogram->Getout_filename(),
"testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".out");
} else if (cres == JE_STATUS) {
retbott.Setcha_result("Challenge Failed");
retbott.Setcha_detail("No SPJ.");
} else {
retbott.Setcha_result("Challenge Success");
string newf = "cha_" + tmpnam();
copyfile(
stdprogram->Getin_filename(),
"testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".in");
copyfile(
stdprogram->Getout_filename(),
"testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".out");
retbott.Setcha_detail(
"Wrong Answer.\nComparator Output Detail:"
"\n--------------------------\n" + cmp->Getdetail() +
"\n--------------------------");
}
//.........这里部分代码省略.........
开发者ID:semprathlon,项目名称:bnuoj-backend,代码行数:101,代码来源:chaclient.cpp
示例16: copyfilepos
/*
* Like copyfile, but takes a position for file f. Returns with
* f and g pointing just past the copied data.
*/
int copyfilepos(FILE * f, FILE * g, word32 longcount, word32 fpos)
{
fseek(f, fpos, SEEK_SET);
return copyfile(f, g, longcount);
}
开发者ID:BoxianLai,项目名称:moxiedev,代码行数:9,代码来源:fileio.c
示例17: filecache_update
void filecache_update(TARGET *t)
{
MD5SUM blobmd5sum;
int haveblobmd5sum = 0;
const char *cachedname;
const char *blobname;
int cacheerror;
if (!t->filecache_generate)
return;
/* If the buildmd5sum is empty, then the file doesn't exist. */
cacheerror = ismd5empty(t->buildmd5sum);
if (cacheerror)
return;
haveblobmd5sum = 0;
cachedname = filecache_getfilename(t, t->buildmd5sum, NULL);
if (!cachedname)
return;
/* Search for the appropriate .link file that matches the target. */
haveblobmd5sum = filecache_findlink(cachedname, blobmd5sum);
/* If we weren't able to determine the target md5sum, do it now. */
if (!haveblobmd5sum)
{
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
LIST *md5callback;
pushsettings( t->settings );
md5callback = var_get( "MD5CALLBACK" );
popsettings( t->settings );
if ( md5callback )
{
luahelper_md5callback(t->boundname, blobmd5sum, md5callback->string);
}
else
{
#endif
md5file(t->boundname, blobmd5sum);
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
}
#endif
memcpy(t->contentmd5sum, blobmd5sum, sizeof(MD5SUM));
if (ismd5empty(t->contentmd5sum))
return;
}
{
/* Is the blob already there? */
time_t blobtime;
blobname = filecache_getfilename(t, blobmd5sum, ".blob");
if (file_time(blobname, &blobtime) == -1)
{
time_t blobpartialtime;
const char *blobpartialname;
if(DEBUG_MD5HASH)
printf("Caching %s as %s\n", t->name, cachedname);
else
printf("Caching %s\n", t->name);
/* Write the new .blob to the cache. */
blobpartialname = filecache_getfilename(t, blobmd5sum, ".blob.partial");
if (file_time(blobpartialname, &blobpartialtime) == -1)
{
if (copyfile(blobpartialname, t->boundname, &
|
请发表评论