您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ utime函数代码示例

51自学网 2021-06-03 09:25:51
  C++
这篇教程C++ utime函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中utime函数的典型用法代码示例。如果您正苦于以下问题:C++ utime函数的具体用法?C++ utime怎么用?C++ utime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了utime函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: run_tests2

void run_tests2(void){  int i;  int64_t arr[SIZE];  int64_t dst[SIZE];  double start_time;  double end_time;  double total_time;  printf("Running tests - 2/n");  srand48(SEED);  total_time = 0.0;  for (i = 0; i < RUNS; i++) {    fill(arr, SIZE);    memcpy(dst, arr, sizeof(int64_t) * SIZE);    start_time = utime();    qsort(dst, SIZE, sizeof(int64_t), simple_cmp2);    end_time = utime();    total_time += end_time - start_time;    verify2(dst, SIZE);  }  printf("stdlib qsort time: %.2f us per iteration/n", total_time / RUNS);#ifndef __linux__  srand48(SEED);  total_time = 0.0;  for (i = 0; i < RUNS; i++) {    fill(arr, SIZE);    memcpy(dst, arr, sizeof(int64_t) * SIZE);    start_time = utime();    heapsort(dst, SIZE, sizeof(int64_t), simple_cmp2);    end_time = utime();    total_time += end_time - start_time;    verify2(dst, SIZE);  }  printf("stdlib heapsort time: %.2f us per iteration/n", total_time / RUNS);  srand48(SEED);  total_time = 0.0;  for (i = 0; i < RUNS; i++) {    fill(arr, SIZE);    memcpy(dst, arr, sizeof(int64_t) * SIZE);    start_time = utime();    mergesort(dst, SIZE, sizeof(int64_t), simple_cmp2);    end_time = utime();    total_time += end_time - start_time;    verify2(dst, SIZE);  }  printf("stdlib mergesort time: %.2f us per iteration/n", total_time / RUNS);#endif  srand48(SEED);  total_time = 0.0;  for (i = 0; i < RUNS; i++) {    fill(arr, SIZE);    memcpy(dst, arr, sizeof(int64_t) * SIZE);    start_time = utime();    sorter2_quick_sort(dst, SIZE);    end_time = utime();    total_time += end_time - start_time;    verify2(dst, SIZE);  }  printf("quick sort time: %.2f us per iteration/n", total_time / RUNS);  srand48(SEED);  total_time = 0.0;  for (i = 0; i < RUNS; i++) {    fill(arr, SIZE);    memcpy(dst, arr, sizeof(int64_t) * SIZE);    start_time = utime();    sorter2_bubble_sort(dst, SIZE);    end_time = utime();    total_time += end_time - start_time;    verify2(dst, SIZE);  }  printf("bubble sort time: %.2f us per iteration/n", total_time / RUNS);  srand48(SEED);  total_time = 0.0;  for (i = 0; i < RUNS; i++) {    fill(arr, SIZE);    memcpy(dst, arr, sizeof(int64_t) * SIZE);    start_time = utime();    sorter2_merge_sort(dst, SIZE);    end_time = utime();    total_time += end_time - start_time;    verify2(dst, SIZE);//.........这里部分代码省略.........
开发者ID:TRANE73,项目名称:sort,代码行数:101,


示例2: set_info_func

static intset_info_func (CameraFilesystem *fs, const char *folder, const char *file,	       CameraFileInfo info, void *data, GPContext *context){	int retval;	char path[1024];	Camera *camera = (Camera*)data;	retval = _get_path (camera->port, folder, file, path, sizeof(path));	if (retval < GP_OK)		return retval;	/* We don't support updating permissions (yet) */	if (info.file.fields & GP_FILE_INFO_PERMISSIONS)		return (GP_ERROR_NOT_SUPPORTED);	if (info.file.fields & GP_FILE_INFO_MTIME) {		struct utimbuf utimbuf;		utimbuf.actime  = info.file.mtime;		utimbuf.modtime = info.file.mtime;		if (utime (path, &utimbuf) != 0) {			gp_context_error (context, _("Could not change "				"time of file '%s' in '%s' (%m)."),				file, folder);			return (GP_ERROR);		}	}#if 0 /* implement this using new api -Marcus */	if (info.file.fields & GP_FILE_INFO_NAME) {        	if (!strcasecmp (info.file.name, file))        	        return (GP_OK);	        /* We really have to rename the poor file... */		if (strlen (folder) == 1) {			snprintf (path_old, sizeof (path_old), "/%s",				  file);			snprintf (path_new, sizeof (path_new), "/%s",				  info.file.name);		} else {			snprintf (path_old, sizeof (path_old), "%s/%s",				  folder, file);			snprintf (path_new, sizeof (path_new), "%s/%s",				  folder, info.file.name);		}                retval = rename (path_old, path_new);		if (retval != 0) {	                switch (errno) {	                case EISDIR:	                        return (GP_ERROR_DIRECTORY_EXISTS);	                case EEXIST:	                        return (GP_ERROR_FILE_EXISTS);	                case EINVAL:	                        return (GP_ERROR_BAD_PARAMETERS);	                case EIO:	                        return (GP_ERROR_IO);	                case ENOMEM:	                        return (GP_ERROR_NO_MEMORY);	                case ENOENT:	                        return (GP_ERROR_FILE_NOT_FOUND);	                default:	                        return (GP_ERROR);	                }	        }	}#endif        return (GP_OK);}
开发者ID:JohnChu,项目名称:Snoopy,代码行数:70,


示例3: site_misc_utime

MODRET site_misc_utime(cmd_rec *cmd) {  if (cmd->argc < 2)    return DECLINED(cmd);  if (strcasecmp(cmd->argv[1], "UTIME") == 0) {    register unsigned int i;    char c, *p, *path = "";    unsigned int year, month, day, hour, min;    struct utimbuf tmbuf;    unsigned char *authenticated;    if (cmd->argc < 4)      return DECLINED(cmd);    authenticated = get_param_ptr(cmd->server->conf, "authenticated", FALSE);    if (!authenticated || *authenticated == FALSE) {      pr_response_add_err(R_530, "Please login with USER and PASS");      return ERROR(cmd);    }    if (strlen(cmd->argv[2]) != 12) {      pr_response_add_err(R_500, "%s: %s", cmd->arg, strerror(EINVAL));      return ERROR(cmd);    }    for (i = 3; i < cmd->argc; i++)      path = pstrcat(cmd->tmp_pool, path, *path ? " " : "", cmd->argv[i], NULL);    if (!dir_check(cmd->tmp_pool, "SITE_UTIME", G_WRITE, path, NULL)) {      pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(EPERM));      return ERROR(cmd);    }    if (site_misc_check_filters(cmd, path) < 0) {      pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(EPERM));      return ERROR(cmd);    }    p = cmd->argv[2];    c = cmd->argv[2][4];    cmd->argv[2][4] = '/0';    year = atoi(p);       cmd->argv[2][4] = c;    p = &(cmd->argv[2][4]);    c = cmd->argv[2][6];    cmd->argv[2][6] = '/0';    month = atoi(p);    cmd->argv[2][6] = c;    p = &(cmd->argv[2][6]);    c = cmd->argv[2][8];    cmd->argv[2][8] = '/0';    day = atoi(p);    cmd->argv[2][8] = c;    p = &(cmd->argv[2][8]);    c = cmd->argv[2][10];    cmd->argv[2][10] = '/0';    hour = atoi(p);    cmd->argv[2][10] = c;    p = &(cmd->argv[2][10]);    min = atoi(p);    tmbuf.actime = tmbuf.modtime = site_misc_mktime(year, month, day, hour,      min);    if (utime(path, &tmbuf) < 0) {      pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(errno));      return ERROR(cmd);    }     pr_response_add(R_200, "SITE %s command successful", cmd->argv[1]);    return HANDLED(cmd);  }  if (strcasecmp(cmd->argv[1], "HELP") == 0)    pr_response_add(R_214, "UTIME <sp> YYYYMMDDhhmm <sp> path");  return DECLINED(cmd);}
开发者ID:OPSF,项目名称:uClinux,代码行数:83,


示例4: main

int main(int ac, char **av){	struct stat stat_buf;	/* struct buffer to hold file info. */	int lc;	const char *msg;	time_t modf_time, access_time;	/* file modification/access time */	msg = parse_opts(ac, av, NULL, NULL);	if (msg != NULL) {		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);	}	setup();	/* set the expected errnos... */	TEST_EXP_ENOS(exp_enos);	for (lc = 0; TEST_LOOPING(lc); lc++) {		tst_count = 0;		/*		 * Invoke utime(2) to set TEMP_FILE access and		 * modification times to that specified by		 * times argument.		 */		TEST(utime(TEMP_FILE, &times));		if (TEST_RETURN == -1) {			TEST_ERROR_LOG(TEST_ERRNO);			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));		} else {			/*			 * Get the modification and access times of			 * temporary file using stat(2).			 */			if (stat(TEMP_FILE, &stat_buf) < 0) {				tst_brkm(TFAIL, cleanup, "stat(2) of "					 "%s failed, error:%d",					 TEMP_FILE, TEST_ERRNO);			}			modf_time = stat_buf.st_mtime;			access_time = stat_buf.st_atime;			/* Now do the actual verification */			if ((modf_time != NEW_TIME) ||			    (access_time != NEW_TIME)) {				tst_resm(TFAIL, "%s access and "					 "modification times not set",					 TEMP_FILE);			} else {				tst_resm(TPASS, "Functionality of "					 "utime(%s, &times) successful",					 TEMP_FILE);			}		}		tst_count++;	/* incr TEST_LOOP counter */	}	cleanup();	tst_exit();}
开发者ID:MohdVara,项目名称:ltp,代码行数:65,


示例5: copy_file

//.........这里部分代码省略.........			}		}		if (!dest_exists) {			int fd;			if ((fd = open(dest, O_WRONLY|O_CREAT, source_stat.st_mode)) < 0 ||					(dfp = fdopen(fd, "w")) == NULL) {				if (fd >= 0)					close(fd);				perror_msg("unable to open `%s'", dest);				fclose (sfp);				return -1;			}		}		if (copy_file_chunk(sfp, dfp, -1) < 0)			status = -1;		if (fclose(dfp) < 0) {			perror_msg("unable to close `%s'", dest);			status = -1;		}		if (fclose(sfp) < 0) {			perror_msg("unable to close `%s'", source);			status = -1;		}			}	else if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) ||	    S_ISSOCK(source_stat.st_mode) || S_ISFIFO(source_stat.st_mode) ||	    S_ISLNK(source_stat.st_mode)) {		if (dest_exists &&		       ((flags & FILEUTILS_FORCE) == 0 || unlink(dest) < 0)) {				perror_msg("unable to remove `%s'", dest);				return -1;			}	} else {		error_msg("internal error: unrecognized file type");		return -1;		}	if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) ||	    S_ISSOCK(source_stat.st_mode)) {		if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) {			perror_msg("unable to create `%s'", dest);			return -1;		}	} else if (S_ISFIFO(source_stat.st_mode)) {		if (mkfifo(dest, source_stat.st_mode) < 0) {			perror_msg("cannot create fifo `%s'", dest);			return -1;		}	} else if (S_ISLNK(source_stat.st_mode)) {		char *lpath;		lpath = xreadlink(source);		if (symlink(lpath, dest) < 0) {			perror_msg("cannot create symlink `%s'", dest);			return -1;		}		free(lpath);#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)		if (flags & FILEUTILS_PRESERVE_STATUS)			if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0)				perror_msg("unable to preserve ownership of `%s'", dest);#endif#ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS		add_to_ino_dev_hashtable(&source_stat, dest);#endif		return 0;	}#ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS	add_to_ino_dev_hashtable(&source_stat, dest);#endifend:	if (flags & FILEUTILS_PRESERVE_STATUS) {		struct utimbuf times;		times.actime = source_stat.st_atime;		times.modtime = source_stat.st_mtime;		if (utime(dest, &times) < 0)			perror_msg("unable to preserve times of `%s'", dest);		if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) {			source_stat.st_mode &= ~(S_ISUID | S_ISGID);			perror_msg("unable to preserve ownership of `%s'", dest);		}		if (chmod(dest, source_stat.st_mode) < 0)			perror_msg("unable to preserve permissions of `%s'", dest);	}	return status;}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:101,


示例6: get_file

/* Retrieve a file 'file' of size 'size' by reading the contents of it from the  * socket 'sock' and write the file with the same name to directory 'directory'.  * Update the last modified time of this file to 'timestamp' on the filesystem. * @Param: sock the socket to read from. * @Param: directory the directory to write the file to. * @Param: size the size of the file being retrieved. * @Param: timestamp the last modified time to set to. * @Return: void. */void get_file(int sock, char* directory, char* file, int size, long int timestamp){	int readlength, readcount = 0, length;	char buffer[CHUNKSIZE];	char fullpath[CHUNKSIZE];	FILE *fp;	//Grab the full path to the file.	strncpy(fullpath, directory, CHUNKSIZE);	strcat(fullpath, "/");	strncat(fullpath, file, CHUNKSIZE-strlen(fullpath));	//Open the file. Overwite if it already exists.	if((fp = fopen(fullpath, "w")) == NULL) {		perror("fopen on get file: ");		exit(1);    }	/* Length computes the size of the file to be read per read call.	 * if the length happens to be more than CHUNKSIZE (256) then read only	 * CHUNKSIZE at max for now.	 */	if((length = size) > CHUNKSIZE){		length = CHUNKSIZE;	}	while( readcount < size ){		/* Compute the reamining length to be read. If the reamining length happens		 * to be more than CHUNKSIZE (256) then read only CHUNKSIZE at max for now		 */		length = size - readcount;		if (length > CHUNKSIZE){			length = CHUNKSIZE;		}		readlength = Readn(sock, &buffer, length);		//Update how many bytes has been read yet.		readcount += readlength;		fwrite(buffer, readlength, 1, fp);			//If there was an error with fwrite.		if(ferror(fp)){    		fprintf(stderr, "A write error occured./n");			Close(sock);			exit(1);		}	}				if((fclose(fp))) {		perror("fclose: ");		exit(1);    }		struct stat sbuf;    struct utimbuf new_times;		if(stat(fullpath, &sbuf) != 0) {    	perror("stat");    	exit(1);    }		//Update the last modified time to 'timestamp' for this file on the filesystem.	new_times.actime = sbuf.st_atime; //Access time.	new_times.modtime = (time_t)timestamp;		if(utime(fullpath, &new_times) < 0) {    	perror("utime");    	exit(1);    }}
开发者ID:ayrus,项目名称:sockets-dropbox,代码行数:81,


示例7: open

int File::write(){#if POSIX    int fd;    ssize_t numwritten;    char *name;    name = this->name->toChars();    fd = open(name, O_CREAT | O_WRONLY | O_TRUNC, 0644);    if (fd == -1)        goto err;    numwritten = ::write(fd, buffer, len);    if (len != numwritten)        goto err2;    if (close(fd) == -1)        goto err;    if (touchtime)    {   struct utimbuf ubuf;        ubuf.actime = ((struct stat *)touchtime)->st_atime;        ubuf.modtime = ((struct stat *)touchtime)->st_mtime;        if (utime(name, &ubuf))            goto err;    }    return 0;err2:    close(fd);    ::remove(name);err:    return 1;#elif _WIN32    HANDLE h;    DWORD numwritten;    char *name;    name = this->name->toChars();    h = CreateFileA(name,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,        FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);    if (h == INVALID_HANDLE_VALUE)        goto err;    if (WriteFile(h,buffer,len,&numwritten,NULL) != TRUE)        goto err2;    if (len != numwritten)        goto err2;    if (touchtime) {        SetFileTime(h, NULL, NULL, &((WIN32_FIND_DATAA *)touchtime)->ftLastWriteTime);    }    if (!CloseHandle(h))        goto err;    return 0;err2:    CloseHandle(h);    DeleteFileA(name);err:    return 1;#else    assert(0);#endif}
开发者ID:WebDrake,项目名称:dmd,代码行数:67,


示例8: proto_handle_get

//.........这里部分代码省略.........	while((token = strtok_r(ptr, delim, &saveptr))) {		switch(c) {			case 0: size = atol(token); break;			case 1: md5 = token; break;			case 2: mode = str2mode(token); break;			case 3: atime = atol(token); break; 			case 4: ctime = atol(token); break;			case 5: mtime = atol(token); break;			case 6: name = token; break;		}		c++;		ptr = NULL;	}	if(c != 7) {		conn_printf(cn, "ERROR Protocol violation (%d)/n", __LINE__);		conn_abort(cn);		return ;	}	int fd = creat(name, O_CREAT|O_TRUNC);	if(fd == -1) {		conn_perror(cn, "WARNING creat()");		return;	}	if(chmod(name,mode)==-1) {		perror("WARNING chmod()");	}	struct utimbuf t;	t.actime = atime;	t.modtime = mtime;	if(utime(name,&t)==-1) {		perror("WARNING utime");	}	// CONTENT	int bytes_left = size;	int r;	md5_state_t md5_state;	unsigned char md5bin[16];	char md5str[33];	md5_init(&md5_state);	while(!cn->abort && bytes_left) {		if(cn->rbuf_len == 0) 			(void)conn_read(cn);		r = MIN(bytes_left, cn->rbuf_len);		if(r) {			write(fd, cn->rbuf, r);			md5_append(&md5_state, (unsigned char*)cn->rbuf, r);			conn_shift(cn,r);			bytes_left -= r;		}		assert(bytes_left >= 0);	}	close(fd);	md5_finish(&md5_state, (unsigned char*)md5bin);	md5bin2str(md5bin, md5str);	// Check md5	if(strcmp(md5str,md5)!=0) {		// Mismatch!
开发者ID:chenmoshushi,项目名称:msync,代码行数:67,


示例9: my_copy

int my_copy(const char *from, const char *to, myf MyFlags){  uint Count;  int new_file_stat, create_flag;  File from_file,to_file;  char buff[IO_SIZE];  struct stat stat_buff,new_stat_buff;  DBUG_ENTER("my_copy");  DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags));  from_file=to_file= -1;  new_file_stat=0;  if (MyFlags & MY_HOLD_ORIGINAL_MODES)		/* Copy stat if possible */    new_file_stat=stat((char*) to, &new_stat_buff);  if ((from_file=my_open(from,O_RDONLY | O_SHARE,MyFlags)) >= 0)  {    if (stat(from,&stat_buff))    {      my_errno=errno;      goto err;    }    if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)      stat_buff=new_stat_buff;    create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;    if ((to_file=  my_create(to,(int) stat_buff.st_mode,			     O_WRONLY | create_flag | O_BINARY | O_SHARE,			     MyFlags)) < 0)      goto err;    while ((Count=my_read(from_file,buff,IO_SIZE,MyFlags)) != 0)	if (Count == (uint) -1 ||	    my_write(to_file,buff,Count,MYF(MyFlags | MY_NABP)))	goto err;    if (my_close(from_file,MyFlags) | my_close(to_file,MyFlags))      DBUG_RETURN(-1);				/* Error on close */    /* Copy modes if possible */    if (MyFlags & MY_HOLD_ORIGINAL_MODES && new_file_stat)	DBUG_RETURN(0);			/* File copyed but not stat */    VOID(chmod(to, stat_buff.st_mode & 07777)); /* Copy modes */#if !defined(MSDOS) && !defined(__WIN__) && !defined(__EMX__) && !defined(OS2) && !defined(__NETWARE__)    VOID(chown(to, stat_buff.st_uid,stat_buff.st_gid)); /* Copy ownership */#endif#if !defined(VMS) && !defined(__ZTC__)    if (MyFlags & MY_COPYTIME)    {      struct utimbuf timep;      timep.actime  = stat_buff.st_atime;      timep.modtime = stat_buff.st_mtime;      VOID(utime((char*) to, &timep)); /* last accessed and modified times */    }#endif    DBUG_RETURN(0);  }err:  if (from_file >= 0) VOID(my_close(from_file,MyFlags));  if (to_file >= 0)   VOID(my_close(to_file,MyFlags));  DBUG_RETURN(-1);} /* my_copy */
开发者ID:OPSF,项目名称:uClinux,代码行数:64,


示例10: wclique

static int wclique(int _n, int w[], unsigned char _a[], int sol[]){     struct dsa _dsa, *dsa = &_dsa;      int i, j, p, max_wt, max_nwt, wth, *used, *nwt, *pos;      xlong_t timer;      n = _n;      wt = &w[1];      a = _a;      record = 0;      rec_level = 0;      rec = &sol[1];      clique = xcalloc(n, sizeof(int));      set = xcalloc(n, sizeof(int));      used = xcalloc(n, sizeof(int));      nwt = xcalloc(n, sizeof(int));      pos = xcalloc(n, sizeof(int));      /* start timer */      timer = xtime();      /* order vertices */      for (i = 0; i < n; i++)      {  nwt[i] = 0;         for (j = 0; j < n; j++)            if (is_edge(dsa, i, j)) nwt[i] += wt[j];      }      for (i = 0; i < n; i++)         used[i] = 0;      for (i = n-1; i >= 0; i--)      {  max_wt = -1;         max_nwt = -1;         for (j = 0; j < n; j++)         {  if ((!used[j]) && ((wt[j] > max_wt) || (wt[j] == max_wt               && nwt[j] > max_nwt)))            {  max_wt = wt[j];               max_nwt = nwt[j];               p = j;            }         }         pos[i] = p;         used[p] = 1;         for (j = 0; j < n; j++)            if ((!used[j]) && (j != p) && (is_edge(dsa, p, j)))               nwt[j] -= wt[p];      }      /* main routine */      wth = 0;      for (i = 0; i < n; i++)      {  wth += wt[pos[i]];         sub(dsa, i, pos, 0, 0, wth);         clique[pos[i]] = record;#if 0         if (utime() >= timer + 5.0)#else         if (xdifftime(xtime(), timer) >= 5.0 - 0.001)#endif         {  /* print current record and reset timer */            xprintf("level = %d (%d); best = %d/n", i+1, n, record);#if 0            timer = utime();#else            timer = xtime();#endif         }      }      xfree(clique);      xfree(set);      xfree(used);      xfree(nwt);      xfree(pos);      /* return the solution found */      for (i = 1; i <= rec_level; i++) sol[i]++;      return rec_level;}
开发者ID:davidwhogg,项目名称:SpectralArchetypes,代码行数:71,


示例11: worker_thread_handler

//.........这里部分代码省略.........                assert(req->error);            }#if defined(_WIN32) || defined(__CYGWIN__)            req->u.fio.win32_attrs = req->error ?                INVALID_FILE_ATTRIBUTES : GetFileAttributes(req->u.fio.file_name);#endif            break;        case AsyncReqSetStat:            {                int err = 0;                if (req->u.fio.set_stat_flags & AsyncReqSetSize) {                    if (truncate(req->u.fio.file_name, (off_t)req->u.fio.statbuf.st_size) < 0) err = errno;                }                if (req->u.fio.set_stat_flags & AsyncReqSetPermissions) {                    if (chmod(req->u.fio.file_name, req->u.fio.statbuf.st_mode) < 0) err = errno;                }#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WRS_KERNEL)#  if defined(_WIN32) || defined(__CYGWIN__)                if (req->u.fio.win32_attrs != INVALID_FILE_ATTRIBUTES) {                    if (SetFileAttributes(req->u.fio.file_name, req->u.fio.win32_attrs) == 0)                        err = set_win32_errno(GetLastError());                }#  endif#else                if (req->u.fio.set_stat_flags & AsyncReqSetUidGid) {                    if (chown(req->u.fio.file_name, req->u.fio.statbuf.st_uid, req->u.fio.statbuf.st_gid) < 0) err = errno;                }#endif                if (req->u.fio.set_stat_flags & AsyncReqSetAcModTime) {                    struct utimbuf buf;                    buf.actime = req->u.fio.statbuf.st_atime;                    buf.modtime = req->u.fio.statbuf.st_mtime;                    if (utime(req->u.fio.file_name, &buf) < 0) err = errno;                }                req->error = err;            }            break;        case AsyncReqFSetStat:            {                int err = 0;                if (req->u.fio.set_stat_flags & AsyncReqSetSize) {                    if (ftruncate(req->u.fio.fd, (off_t)req->u.fio.statbuf.st_size) < 0) err = errno;                }#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WRS_KERNEL)                if (req->u.fio.set_stat_flags & AsyncReqSetPermissions) {                    if (chmod(req->u.fio.file_name, req->u.fio.statbuf.st_mode) < 0) err = errno;                }#  if defined(_WIN32) || defined(__CYGWIN__)                if (req->u.fio.win32_attrs != INVALID_FILE_ATTRIBUTES) {                    if (SetFileAttributes(req->u.fio.file_name, req->u.fio.win32_attrs) == 0)                        err = set_win32_errno(GetLastError());                }#  endif#else                if (req->u.fio.set_stat_flags & AsyncReqSetUidGid) {                    if (fchown(req->u.fio.fd, req->u.fio.statbuf.st_uid, req->u.fio.statbuf.st_gid) < 0) err = errno;                }                if (req->u.fio.set_stat_flags & AsyncReqSetPermissions) {                    if (fchmod(req->u.fio.fd, req->u.fio.statbuf.st_mode) < 0) err = errno;                }#endif                if (req->u.fio.set_stat_flags & AsyncReqSetAcModTime) {                    struct utimbuf buf;                    buf.actime = req->u.fio.statbuf.st_atime;
开发者ID:tom3333,项目名称:tcf.agent,代码行数:67,


示例12: copyfile

static voidcopyfile( char *name, char *toname, mode_t mode, char *group, char *owner,          int dotimes, uid_t uid, gid_t gid ){  int fromfd, tofd, cc, wc, exists;  char buf[BUFSIZ], *bp;  struct stat sb, tosb;  struct utimbuf utb;  exists = (lstat(toname, &tosb) == 0);  fromfd = open(name, O_RDONLY);  if (fromfd < 0 || fstat(fromfd, &sb) < 0)    fail("cannot access %s", name);  if (exists && (!S_ISREG(tosb.st_mode) || access(toname, W_OK) < 0))    (void) (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname);  tofd = open(toname, O_CREAT | O_WRONLY, 0666);  if (tofd < 0)    fail("cannot create %s", toname);  bp = buf;  while ((cc = read(fromfd, bp, sizeof buf)) > 0)  {    while ((wc = write(tofd, bp, (unsigned int)cc)) > 0)    {      if ((cc -= wc) == 0)        break;      bp += wc;    }    if (wc < 0)      fail("cannot write to %s", toname);  }  if (cc < 0)    fail("cannot read from %s", name);  if (ftruncate(tofd, sb.st_size) < 0)    fail("cannot truncate %s", toname);#if !defined(VMS)  if (dotimes)  {    utb.actime = sb.st_atime;    utb.modtime = sb.st_mtime;    if (utime(toname, &utb) < 0)      fail("cannot set times of %s", toname);  }#ifdef HAVE_FCHMOD  if (fchmod(tofd, mode) < 0)#else  if (chmod(toname, mode) < 0)#endif    fail("cannot change mode of %s", toname);#endif  if ((owner || group) && fchown(tofd, uid, gid) < 0)    fail("cannot change owner of %s", toname);  /* Must check for delayed (NFS) write errors on close. */  if (close(tofd) < 0)    fail("cannot write to %s", toname);  close(fromfd);#if defined(VMS)  if (chmod(toname, (mode & (S_IREAD | S_IWRITE))) < 0)    fail("cannot change mode of %s", toname);  if (dotimes)  {    utb.actime = sb.st_atime;    utb.modtime = sb.st_mtime;    if (utime(toname, &utb) < 0)      fail("cannot set times of %s", toname);  }#endif}
开发者ID:rn10950,项目名称:RetroZilla,代码行数:71,


示例13: incremental

//.........这里部分代码省略.........						total++;						idset_add(deleteset, n_fid);					}				}			}		}		find_close();		/*		 * make delete list.		 */		if (remove_lost) {			limit = gpath_nextkey();		} else {			limit = 0;		}		for (id = 1; id < limit; id++) {			char fid[MAXFIDLEN];			int type;			snprintf(fid, sizeof(fid), "%d", id);			/*			 * This is a hole of GPATH. The hole increases if the deletion			 * and the addition are repeated.			 */			if ((path = gpath_fid2path(fid, &type)) == NULL)				continue;			/*			 * The file which does not exist in the findset is treated			 * assuming that it does not exist in the file system.			 */			if (type == GPATH_OTHER) {				if (!idset_contains(findset, id) || !test("f", path) || test("b", path))					strbuf_puts0(deletelist, path);			} else {				if (!idset_contains(findset, id) || !test("f", path)) {					strbuf_puts0(deletelist, path);					idset_add(deleteset, id);				}			}		}	}	gpath_close();	statistics_time_end(tim);	/*	 * execute updating.	 */	if ((!idset_empty(deleteset) || strbuf_getlen(addlist) > 0) ||	    (strbuf_getlen(deletelist) + strbuf_getlen(addlist_other) > 0))	{		int db;		updated = 1;		tim = statistics_time_start("Time of updating %s and %s.", dbname(GTAGS), dbname(GRTAGS));		if (!idset_empty(deleteset) || strbuf_getlen(addlist) > 0)			updatetags(dbpath, root, deleteset, addlist);		if (strbuf_getlen(deletelist) + strbuf_getlen(addlist_other) > 0) {			const char *start, *end, *p;			if (vflag)				fprintf(stderr, "[%s] Updating '%s'./n", now(), dbname(GPATH));			gpath_open(dbpath, 2);			if (strbuf_getlen(deletelist) > 0) {				start = strbuf_value(deletelist);				end = start + strbuf_getlen(deletelist);				for (p = start; p < end; p += strlen(p) + 1)					gpath_delete(p);			}			if (strbuf_getlen(addlist_other) > 0) {				start = strbuf_value(addlist_other);				end = start + strbuf_getlen(addlist_other);				for (p = start; p < end; p += strlen(p) + 1)					gpath_put(p, GPATH_OTHER);			}			gpath_close();		}		/*		 * Update modification time of tag files		 * because they may have no definitions.		 */		for (db = GTAGS; db < GTAGLIM; db++)			utime(makepath(dbpath, dbname(db), NULL), NULL);		statistics_time_end(tim);	}	if (vflag) {		if (updated)			fprintf(stderr, " Global databases have been modified./n");		else			fprintf(stderr, " Global databases are up to date./n");		fprintf(stderr, "[%s] Done./n", now());	}	strbuf_close(addlist);	strbuf_close(deletelist);	strbuf_close(addlist_other);	idset_close(deleteset);	idset_close(findset);	return updated;}
开发者ID:baohaojun,项目名称:ajoke-global,代码行数:101,


示例14: cppath

//.........这里部分代码省略.........	 * --> use the mode of the source (srcStatbuf.st_mode) but mask off all	 * --> non-access mode bits (remove SET?UID bits)	 * - otherwise:	 * --> use 0666	 */	if (a_ctrl & MODE_SET) {		mode_t	usemode;		usemode = (a_mode ^ BADMODE) ? a_mode : 0644;		if (a_mode != usemode && usemode == 0644) {			logerr(WRN_DEF_MODE, a_dstPath);			a_mode = usemode;		}	} else if (a_ctrl & MODE_SRC) {		a_mode = (srcStatbuf.st_mode & S_IAMB);	} else {		a_mode = 0666;	}	/*	 * Get fd of newly created destination file or, if this	 * is an overwrite,  a temporary file (linknam).	 */	dstFd = write_file(&linknam, a_ctrl, a_mode, a_dstPath);	if (dstFd < 0) {		(void) close(srcFd);		return (1);	}	/*	 * source and target files are open: copy data	 */	status = copyFile(srcFd, dstFd, a_srcPath, a_dstPath, &srcStatbuf, 0);	(void) close(srcFd);	(void) close(dstFd);	if (status != 0) {		progerr(ERR_INPUT, a_srcPath, errno, strerror(errno));		if (linknam) {			(void) remove(linknam);		}		return (1);	}	/*	 * If this is an overwrite, rename temp over original	 */	if ((linknam != (char *)NULL) && (rename(linknam, a_dstPath) != 0)) {		FILE	*logfp = (FILE *)NULL;		char	busylog[PATH_MAX];		/* output log message if busy else program error */		if (errno == ETXTBSY) {			logerr(MSG_PROCMV, linknam);		} else {			progerr(ERR_OUTPUT_WRITING, a_dstPath, errno,				strerror(errno));		}		(void) remove(linknam);		/* open the log file and append log entry */		len = snprintf(busylog, sizeof (busylog),				"%s/textbusy", get_PKGADM());		if (len > sizeof (busylog)) {			progerr(ERR_CREATE_PATH_2, get_PKGADM(),				"textbusy");		} else {			logfp = fopen(busylog, "a");			if (logfp == NULL) {				progerr(ERR_LOG, busylog, errno,					strerror(errno));			} else {				(void) fprintf(logfp, "%s/n", linknam);				(void) fclose(logfp);			}		}	}	/* set access/modification times for target */	times.actime = srcStatbuf.st_atime;	times.modtime = srcStatbuf.st_mtime;	if (utime(a_dstPath, &times) != 0) {		progerr(ERR_MODTIM, a_dstPath, errno, strerror(errno));		return (1);	}	/* success! */	return (0);}
开发者ID:belenix,项目名称:belenixold,代码行数:101,


示例15: sim_make_ROM_include

//.........这里部分代码省略.........    }if (stat (rom_filename, &statb)) {    printf ("Error stating '%s': %s/n", rom_filename, strerror(errno));    fclose (rFile);    return -1;    }if (statb.st_size != expected_size) {    printf ("Error: ROM file '%s' has an unexpected size: %d vs %d/n", rom_filename, (int)statb.st_size, expected_size);    printf ("This can happen if the file was transferred or unpacked incorrectly/n");    printf ("and in the process tried to convert line endings rather than passing/n");    printf ("the file's contents unmodified/n");    fclose (rFile);    return -1;    }ROMData = (unsigned char *)malloc (statb.st_size);if ((size_t)(statb.st_size) != fread (ROMData, sizeof(*ROMData), statb.st_size, rFile)) {    printf ("Error reading '%s': %s/n", rom_filename, strerror(errno));    fclose (rFile);    free (ROMData);    return -1;    }fclose (rFile);for (c=0; c<statb.st_size; ++c)    checksum += ROMData[c];checksum = ~checksum;if ((expected_checksum != 0) && (checksum != expected_checksum)) {    printf ("Error: ROM file '%s' has an unexpected checksum: 0x%08X vs 0x%08X/n", rom_filename, checksum, expected_checksum);    printf ("This can happen if the file was transferred or unpacked incorrectly/n");    printf ("and in the process tried to convert line endings rather than passing/n");    printf ("the file's contents unmodified/n");    free (ROMData);    return -1;    }/* * If the target include file already exists, determine if it contains the exact * data in the base ROM image.  If so, then we are already done */if (0 == sim_read_ROM_include(include_filename,                               &include_bytes,                              &include_ROMData,                              &include_checksum,                              &include_array_name,                              &defines_found)) {    c = ((include_checksum == expected_checksum) &&          (include_bytes == expected_size) &&         (0 == strcmp (include_array_name, rom_array_name)) &&         (0 == memcmp (include_ROMData, ROMData, include_bytes)) &&         defines_found);    free(include_ROMData);    free(include_array_name);    if (c) {        free (ROMData);        return 0;        }    }if (NULL == (iFile = fopen (include_filename, "w"))) {    printf ("Error Opening '%s' for output: %s/n", include_filename, strerror(errno));    free (ROMData);    return -1;    }load_filename = strrchr (rom_filename, '/');if (load_filename)    ++load_filename;else    load_filename = rom_filename;time (&now);fprintf (iFile, "#ifndef ROM_%s_H/n", rom_array_name);fprintf (iFile, "#define ROM_%s_H 0/n", rom_array_name);fprintf (iFile, "/*/n");fprintf (iFile, "   %s         produced at %s", include_filename, ctime(&now));fprintf (iFile, "   from %s which was last modified at %s", rom_filename, ctime(&statb.st_mtime));fprintf (iFile, "   file size: %d (0x%X) - checksum: 0x%08X/n", (int)statb.st_size, (int)statb.st_size, checksum);fprintf (iFile, "   This file is a generated file and should NOT be edited or changed by hand./n");if (Comments)    fprintf (iFile, "/n   %s/n/n", Comments);fprintf (iFile, "*//n");fprintf (iFile, "#define BOOT_CODE_SIZE 0x%X/n", (int)statb.st_size);fprintf (iFile, "#define BOOT_CODE_FILENAME /"%s/"/n", load_filename);fprintf (iFile, "#define BOOT_CODE_ARRAY %s/n", rom_array_name);fprintf (iFile, "unsigned char %s[] = {", rom_array_name);for (bytes_written=0;bytes_written<statb.st_size; ++bytes_written) {    c = ROMData[bytes_written];    if (0 == bytes_written%16)        fprintf (iFile,"/n");    fprintf (iFile,"0x%02X,", c&0xFF);    }free (ROMData);fprintf (iFile,"};/n");fprintf (iFile, "#endif /* ROM_%s_H *//n", rom_array_name);fclose (iFile);if (1) { /* Set Modification Time on the include file to be the modification time of the ROM file */    struct utimbuf times;    times.modtime = statb.st_mtime;    times.actime = statb.st_atime;    utime (include_filename, &times);    }return 0;}
开发者ID:rcornwell,项目名称:sims,代码行数:101,


示例16: my_copy

int my_copy(const char *from, const char *to, myf MyFlags){  size_t Count;  my_bool new_file_stat= 0; /* 1 if we could stat "to" */  int create_flag;  File from_file,to_file;  uchar buff[IO_SIZE];  MY_STAT stat_buff,new_stat_buff;  DBUG_ENTER("my_copy");  DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags));  from_file=to_file= -1;  DBUG_ASSERT(!(MyFlags & (MY_FNABP | MY_NABP))); /* for my_read/my_write */  if (MyFlags & MY_HOLD_ORIGINAL_MODES)		/* Copy stat if possible */    new_file_stat= test(my_stat((char*) to, &new_stat_buff, MYF(0)));  if ((from_file=my_open(from,O_RDONLY | O_SHARE,MyFlags)) >= 0)  {    if (!my_stat(from, &stat_buff, MyFlags))    {      my_errno=errno;      goto err;    }    if (MyFlags & MY_HOLD_ORIGINAL_MODES && new_file_stat)      stat_buff=new_stat_buff;    create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;    if ((to_file=  my_create(to,(int) stat_buff.st_mode,			     O_WRONLY | create_flag | O_BINARY | O_SHARE,			     MyFlags)) < 0)      goto err;    while ((Count=my_read(from_file, buff, sizeof(buff), MyFlags)) != 0)    {	if (Count == (uint) -1 ||	    my_write(to_file,buff,Count,MYF(MyFlags | MY_NABP)))	goto err;    }    /* sync the destination file */    if (MyFlags & MY_SYNC)    {      if (my_sync(to_file, MyFlags))        goto err;    }    if (my_close(from_file,MyFlags) | my_close(to_file,MyFlags))      DBUG_RETURN(-1);				/* Error on close */    /* Copy modes if possible */    if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)	DBUG_RETURN(0);			/* File copyed but not stat */    /* Copy modes */    if (chmod(to, stat_buff.st_mode & 07777))    {      my_errno= errno;      if (MyFlags & (MY_FAE+MY_WME))      {        char  errbuf[MYSYS_STRERROR_SIZE];        my_error(EE_CHANGE_PERMISSIONS, MYF(ME_BELL+ME_WAITTANG), from,                 errno, my_strerror(errbuf, sizeof(errbuf), errno));      }      goto err;    }#if !defined(__WIN__)    /* Copy ownership */    if (chown(to, stat_buff.st_uid, stat_buff.st_gid))    {      my_errno= errno;      if (MyFlags & (MY_FAE+MY_WME))      {        char  errbuf[MYSYS_STRERROR_SIZE];        my_error(EE_CHANGE_OWNERSHIP, MYF(ME_BELL+ME_WAITTANG), from,                 errno, my_strerror(errbuf, sizeof(errbuf), errno));      }      goto err;    }#endif    if (MyFlags & MY_COPYTIME)    {      struct utimbuf timep;      timep.actime  = stat_buff.st_atime;      timep.modtime = stat_buff.st_mtime;      (void) utime((char*) to, &timep); /* last accessed and modified times */    }    DBUG_RETURN(0);  }err:  if (from_file >= 0) (void) my_close(from_file,MyFlags);  if (to_file >= 0)  {    (void) my_close(to_file, MyFlags);    /* attempt to delete the to-file we've partially written */    (void) my_delete(to, MyFlags);  }  DBUG_RETURN(-1);//.........这里部分代码省略.........
开发者ID:Andrew8305,项目名称:inception,代码行数:101,


示例17: main

int main(int ac, char **av){	struct stat stat_buf;	/* struct buffer to hold file info. */	int lc;	long type;	time_t modf_time, access_time;	time_t pres_time;	/* file modification/access/present time */	tst_parse_opts(ac, av, NULL, NULL);	setup();	switch ((type = tst_fs_type(cleanup, "."))) {	case TST_NFS_MAGIC:		if (tst_kvercmp(2, 6, 18) < 0)			tst_brkm(TCONF, cleanup, "Cannot do utime on a file"				" on %s filesystem before 2.6.18",				 tst_fs_type_name(type));		break;	case TST_V9FS_MAGIC:		tst_brkm(TCONF, cleanup,			 "Cannot do utime on a file on %s filesystem",			 tst_fs_type_name(type));		break;	}	for (lc = 0; TEST_LOOPING(lc); lc++) {		tst_count = 0;		/*		 * Invoke utime(2) to set TEMP_FILE access and		 * modification times to the current time.		 */		TEST(utime(TEMP_FILE, NULL));		if (TEST_RETURN == -1) {			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));		} else {			/*			 * Sleep for a second so that mod time and			 * access times will be different from the			 * current time			 */			sleep(2);			/*			 * Get the current time now, after calling			 * utime(2)			 */			if ((pres_time = time(&tloc)) < 0) {				tst_brkm(TFAIL, cleanup, "time() "					 "failed to get present time "					 "after utime, error=%d",					 errno);			}			/*			 * Get the modification and access times of			 * temporary file using stat(2).			 */			if (stat(TEMP_FILE, &stat_buf) < 0) {				tst_brkm(TFAIL, cleanup, "stat(2) of "					 "%s failed, error:%d",					 TEMP_FILE, TEST_ERRNO);			}			modf_time = stat_buf.st_mtime;			access_time = stat_buf.st_atime;			/* Now do the actual verification */			if (modf_time <= curr_time ||			    modf_time >= pres_time ||			    access_time <= curr_time ||			    access_time >= pres_time) {				tst_resm(TFAIL, "%s access and "					 "modification times not set",					 TEMP_FILE);			} else {				tst_resm(TPASS, "Functionality of "					 "utime(%s, NULL) successful",					 TEMP_FILE);			}		}		tst_count++;	}	cleanup();	tst_exit();}
开发者ID:foss-for-synopsys-dwc-arc-processors,项目名称:ltp,代码行数:90,


示例18: main

//.........这里部分代码省略.........		/* 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 = (char*)xmalloc(len + 1);		    sprintf(linkname, "%s/%s", linkprefix, name);		} else if (dorelsymlink) {		    /* Symlink the relative path from todir to source name. */		    linkname = (char*)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, len) != 0)) {		(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. */	    fromfd = open(name, O_RDONLY);	    if (fromfd < 0 || fstat(fromfd, &sb) < 0)		fail("cannot access %s", name);	    if (exists && (!S_ISREG(tosb.st_mode) || access(toname, W_OK) < 0))		(void) (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname);	    tofd = open(toname, O_CREAT | O_WRONLY, 0666);	    if (tofd < 0)		fail("cannot create %s", toname);	    bp = buf;	    while ((cc = read(fromfd, bp, sizeof buf)) > 0) {		while ((wc = write(tofd, bp, cc)) > 0) {		    if ((cc -= wc) == 0)			break;		    bp += wc;		}		if (wc < 0)		    fail("cannot write to %s", toname);	    }	    if (cc < 0)		fail("cannot read from %s", name);	    if (ftruncate(tofd, sb.st_size) < 0)		fail("cannot truncate %s", toname);	    if (dotimes) {		utb.actime = sb.st_atime;		utb.modtime = sb.st_mtime;		if (utime(toname, &utb) < 0)		    fail("cannot set times of %s", toname);	    }#ifdef HAVE_FCHMOD	    if (fchmod(tofd, mode) < 0)#else	    if (chmod(toname, mode) < 0)#endif		fail("cannot change mode of %s", toname);	    if ((owner || group) && fchown(tofd, uid, gid) < 0)		fail("cannot change owner of %s", toname);	    /* Must check for delayed (NFS) write errors on close. */	    if (close(tofd) < 0)		fail("cannot write to %s", toname);	    close(fromfd);	}	free(toname);    }    free(cwd);    free(todir);    return 0;}
开发者ID:EdgarChen,项目名称:mozilla-cvs-history,代码行数:101,


示例19: uv__fs_utime

static ssize_t uv__fs_utime(uv_fs_t* req) {  struct utimbuf buf;  buf.actime = req->atime;  buf.modtime = req->mtime;  return utime(req->path, &buf); /* TODO use utimes() where available */}
开发者ID:AndreasBriese,项目名称:node9,代码行数:6,


示例20: dexopt

//.........这里部分代码省略.........     * precompiled the apk and there is nothing to do here.     */    sprintf(out_path, "%s%s", apk_path, ".odex");    if (stat(out_path, &dex_stat) == 0) {        return 0;    }    if (create_cache_path(out_path, apk_path)) {        return -1;    }    memset(&apk_stat, 0, sizeof(apk_stat));    stat(apk_path, &apk_stat);    zip_fd = open(apk_path, O_RDONLY, 0);    if (zip_fd < 0) {        ALOGE("installd cannot open '%s' for input during dexopt/n", apk_path);        return -1;    }    unlink(out_path);    out_fd = open(out_path, O_RDWR | O_CREAT | O_EXCL, 0644);    if (out_fd < 0) {        ALOGE("installd cannot open '%s' for output during dexopt/n", out_path);        goto fail;    }    if (fchmod(out_fd,               S_IRUSR|S_IWUSR|S_IRGRP |               (is_public ? S_IROTH : 0)) < 0) {        ALOGE("installd cannot chmod '%s' during dexopt/n", out_path);        goto fail;    }    if (fchown(out_fd, AID_SYSTEM, uid) < 0) {        ALOGE("installd cannot chown '%s' during dexopt/n", out_path);        goto fail;    }    ALOGV("DexInv: --- BEGIN '%s' ---/n", apk_path);    pid_t pid;    pid = fork();    if (pid == 0) {        /* child -- drop privileges before continuing */        if (setgid(uid) != 0) {            ALOGE("setgid(%d) failed in installd during dexopt/n", uid);            exit(64);        }        if (setuid(uid) != 0) {            ALOGE("setuid(%d) failed in installd during dexopt/n", uid);            exit(65);        }        // drop capabilities        struct __user_cap_header_struct capheader;        struct __user_cap_data_struct capdata[2];        memset(&capheader, 0, sizeof(capheader));        memset(&capdata, 0, sizeof(capdata));        capheader.version = _LINUX_CAPABILITY_VERSION_3;        if (capset(&capheader, &capdata[0]) < 0) {            ALOGE("capset failed: %s/n", strerror(errno));            exit(66);        }        if (flock(out_fd, LOCK_EX | LOCK_NB) != 0) {            ALOGE("flock(%s) failed: %s/n", out_path, strerror(errno));            exit(67);        }        if (strncmp(persist_sys_dalvik_vm_lib, "libdvm", 6) == 0) {            run_dexopt(zip_fd, out_fd, apk_path, out_path, dexopt_flags);        } else if (strncmp(persist_sys_dalvik_vm_lib, "libart", 6) == 0) {            run_dex2oat(zip_fd, out_fd, apk_path, out_path, dexopt_flags);        } else {            exit(69);   /* Unexpected persist.sys.dalvik.vm.lib value */        }        exit(68);   /* only get here on exec failure */    } else {        res = wait_dexopt(pid, apk_path);        if (res != 0) {            ALOGE("dexopt in='%s' out='%s' res=%d/n", apk_path, out_path, res);            goto fail;        }    }    ut.actime = apk_stat.st_atime;    ut.modtime = apk_stat.st_mtime;    utime(out_path, &ut);    close(out_fd);    close(zip_fd);    return 0;fail:    if (out_fd >= 0) {        close(out_fd);        unlink(out_path);    }    if (zip_fd >= 0) {        close(zip_fd);    }    return -1;}
开发者ID:IOAP,项目名称:android_frameworks_native,代码行数:101,


示例21: main

int main(int ac, char **av){	struct stat stat_buf;	/* struct buffer to hold file info. */	int lc;	long type;	const char *msg;	time_t modf_time, access_time;	time_t pres_time;	/* file modification/access/present time */	pid_t pid;	msg = parse_opts(ac, av, NULL, NULL);	if (msg != NULL) {		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);	}	setup();	switch ((type = tst_fs_type(cleanup, "."))) {	case TST_NFS_MAGIC:	case TST_V9FS_MAGIC:		tst_brkm(TCONF, cleanup,			 "Cannot do utime on a file on %s filesystem",			 tst_fs_type_name(type));	break;	}	/* set the expected errnos... */	TEST_EXP_ENOS(exp_enos);	pid = FORK_OR_VFORK();	if (pid == -1) {		tst_brkm(TBROK, cleanup, "fork() failed");	} else if (pid == 0) {		if ((ltpuser = getpwnam(LTPUSER1)) == NULL) {			tst_brkm(TBROK, cleanup, "%s not found in /etc/passwd",				 LTPUSER1);		}		/* get uid/gid of user accordingly */		user_uid = ltpuser->pw_uid;		seteuid(user_uid);		for (lc = 0; TEST_LOOPING(lc); lc++) {			tst_count = 0;			/*			 * Invoke utime(2) to set TEMP_FILE access and			 * modification times to the current time.			 */			TEST(utime(TEMP_FILE, NULL));			if (TEST_RETURN == -1) {				TEST_ERROR_LOG(TEST_ERRNO);				tst_resm(TFAIL,					 "utime(%s) Failed, errno=%d : %s",					 TEMP_FILE, TEST_ERRNO,					 strerror(TEST_ERRNO));			} else {				/*				 * Sleep for a second so that mod time				 * and access times will be different				 * from the current time.				 */				sleep(2);				/*				 * Get the current time now, after				 * calling utime(2)				 */				if ((pres_time = time(&tloc)) < 0) {					tst_brkm(TFAIL, cleanup,						 "time() failed to get "						 "present time after "						 "utime, error=%d",						 errno);				}				/*				 * Get the modification and access				 * times of temporary file using				 * stat(2).				 */				if (stat(TEMP_FILE, &stat_buf) < 0) {					tst_brkm(TFAIL, cleanup,						 "stat(2) of %s failed, "						 "error:%d", TEMP_FILE,						 TEST_ERRNO);				}				modf_time = stat_buf.st_mtime;				access_time = stat_buf.st_atime;				/* Now do the actual verification */				if (modf_time <= curr_time ||				    modf_time >= pres_time ||				    access_time <= curr_time ||				    access_time >= pres_time) {//.........这里部分代码省略.........
开发者ID:gibertre,项目名称:ltp,代码行数:101,


示例22: main

//.........这里部分代码省略.........    hd = -1;    }  /* If a blocking call timed out, break the retry loop if the total time  so far is not less than than retries * interval. */  if (sigalrm_seen &&      (j + 1) * ((lock_fcntl_timeout > lock_flock_timeout)?        lock_fcntl_timeout : lock_flock_timeout) >=          lock_retries * lock_interval)    j = lock_retries;  /* Wait a bit before retrying, except when it was a blocked fcntl() that  caused the problem. */  if (j < lock_retries && sleep_before_retry)    {    printf(" ... waiting/n");    sleep(lock_interval);    }  }if (j >= lock_retries)  {  printf("exim_lock: locking failed too many times/n");  yield = 1;  goto CLEAN_UP;  }if (!quiet) printf("exim_lock: locking %s succeeded: ", filename);/* If there are no further arguments, run the user's shell; otherwisethe next argument is a command to run. */if (i >= argc)  {  command = getenv("SHELL");  if (command == NULL || *command == 0) command = "/bin/sh";  if (!quiet) printf("running %s .../n", command);  }else  {  command = argv[i];  if (!quiet) printf("running the command .../n");  }/* Run the command, saving and restoring the times if required. */if (restore_times)  {  struct stat strestore;  struct utimbuf ut;  stat(filename, &strestore);  (void)system(command);  ut.actime = strestore.st_atime;  ut.modtime = strestore.st_mtime;  utime(filename, &ut);  }else (void)system(command);/* Remove the locks and exit. Unlink the /tmp file if we can get an exclusivelock on the mailbox. This should be a non-blocking lock call, as there is nopoint in waiting. */CLEAN_UP:if (md >= 0)  {  if (apply_lock(fd, F_WRLCK, use_fcntl, 0, use_flock, 0) >= 0)    {    if (!quiet) printf("exim_lock: %s unlinked - no sharers/n", tempname);    unlink(tempname);    }  else if (!quiet)    printf("exim_lock: %s not unlinked - unable to get exclusive mailbox lock/n",      tempname);  if (close(md) < 0)    printf("exim_lock: close %s failed: %s/n", tempname, strerror(errno));  else    if (!quiet) printf("exim_lock: %s closed/n", tempname);  }if (fd >= 0)  {  if (close(fd) < 0)    printf("exim_lock: close %s failed: %s/n", filename, strerror(errno));  else    if (!quiet) printf("exim_lock: %s closed/n", filename);  }if (hd >= 0)  {  if (unlink(lockname) < 0)    printf("exim_lock: unlink %s failed: %s/n", lockname, strerror(errno));  else    if (!quiet) printf("exim_lock: lock file removed/n");  }return yield;}
开发者ID:mosqutip,项目名称:EECS395-27,代码行数:101,


示例23: move_file

int move_file(struct flist * file, off_t wsize){	char *from, *to, *buf;	off_t size;	FILE *input, *output;	int ret, dir_id;	struct utimbuf ftime = {0};	struct statvfs svf;	fsblkcnt_t space;	struct stat st;	mhdd_debug(MHDD_MSG, "move_file: %s/n", file->real_name);	/* TODO: it would be nice to contrive something alter */	flist_wrlock_locked();	from=file->real_name;	/* We need to check if already moved */	if (statvfs(from, &svf) != 0)		return -errno;	space = svf.f_bsize;	space *= svf.f_bavail;	/* get file size */	if (fstat(file->fh, &st) != 0) {		mhdd_debug(MHDD_MSG, "move_file: error stat %s: %s/n",			from, strerror(errno));		return -errno;	}        /* Hard link support is limited to a single device, and files with           >1 hardlinks cannot be moved between devices since this would           (a) result in partial files on the source device (b) not free           the space from the source device during unlink. */	if (st.st_nlink > 1) {		mhdd_debug(MHDD_MSG, "move_file: cannot move "			"files with >1 hardlinks/n");		return -ENOTSUP;	}	size = st.st_size;	if (size < wsize) size=wsize;	if (space > size) {		mhdd_debug(MHDD_MSG, "move_file: we have enough space/n");		return 0;	}	if ((dir_id=find_free_space(size)) == -1) {		mhdd_debug(MHDD_MSG, "move_file: can not find space/n");		return -1;	}	if (!(input = fopen(from, "r")))		return -errno;	create_parent_dirs(dir_id, file->name);	to = create_path(mhdd.dirs[dir_id], file->name);	if (!(output = fopen(to, "w+"))) {		ret = -errno;		mhdd_debug(MHDD_MSG, "move_file: error create %s: %s/n",				to, strerror(errno));		free(to);		fclose(input);		return(ret);	}	mhdd_debug(MHDD_MSG, "move_file: move %s to %s/n", from, to);	// move data	buf=(char *)calloc(sizeof(char), MOVE_BLOCK_SIZE);	while((size = fread(buf, sizeof(char), MOVE_BLOCK_SIZE, input))) {		if (size != fwrite(buf, sizeof(char), size, output)) {			mhdd_debug(MHDD_MSG,				"move_file: error move data to %s: %s/n",				to, strerror(errno));			fclose(output);			fclose(input);			free(buf);			unlink(to);			free(to);			return -1;		}	}	free(buf);	mhdd_debug(MHDD_MSG, "move_file: done move data/n");	fclose(input);	// owner/group/permissions	fchmod(fileno(output), st.st_mode);	fchown(fileno(output), st.st_uid, st.st_gid);	fclose(output);	// time	ftime.actime = st.st_atime;	ftime.modtime = st.st_mtime;	utime(to, &ftime);//.........这里部分代码省略.........
开发者ID:Leatherface75,项目名称:mhddfs-nosegfault,代码行数:101,


示例24: assert

//.........这里部分代码省略.........		if( ctx->outfile == ParserContext::OF_STDOUT )			out_fp = stdout;		else {#if SANITY_CHECK			assert( ! ctx->baksuffix.isnull() );#endif			if( ctx->baksuffix[0] != ParserContext::MAGIC_CHAR )				bak_fname = infile->name + ctx->baksuffix;			else				out_fname = infile->name;			int fd;			char tmp_outfile[32];			strcpy(tmp_outfile, "@[email
C++ utimensat函数代码示例
C++ util_unreference_framebuffer_state函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。