• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rename函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: write_config

/*
 * Write a configuration to the config file.
 */
static void write_config(struct config_s *config)
{
#ifdef WINDOWS
    remove(CONFIG_BAK_FILENAME);    // For windows rename() bug.
#endif
    if (rename(CONFIG_FILENAME, CONFIG_BAK_FILENAME) != 0 && errno != ENOENT)
    {
        warning("unable to back-up old configuation file \"%s\" to \"%s\"",
            CONFIG_FILENAME, CONFIG_BAK_FILENAME);
    }
    errno = 0;

    FILE *file = fopen(CONFIG_TMP_FILENAME, "w");
    if (file == NULL)
    {
        warning("unable to open configuration file \"%s\" for writing",
            CONFIG_TMP_FILENAME);
        return;
    }
    fprintf(file, "# %s configuration file\n", PROGRAM_NAME_LONG);
    fputs("# AUTOMATICALLY GENERATED, DO NOT EDIT\n", file);
    fputc('\n', file);
    fprintf(file, "%s = \"%s\"\n", VAR_ENABLED,
        bool_to_string(config->enabled));
    fprintf(file, "%s = \"%s\"\n", VAR_HIDE_TCP,
        bool_to_string(config->hide_tcp));
    fprintf(file, "%s = \"%s\"\n", VAR_HIDE_TCP_DATA,
        bool_to_string(config->hide_tcp_data));
    fprintf(file, "%s = \"%s\"\n", VAR_HIDE_TCP_SYN,
        enum_to_string(config->hide_tcp_syn, flag_def, DEF_SIZE(flag_def)));
    fprintf(file, "%s = \"%s\"\n", VAR_HIDE_TCP_ACK,
        enum_to_string(config->hide_tcp_ack, flag_def, DEF_SIZE(flag_def)));
    fprintf(file, "%s = \"%s\"\n", VAR_HIDE_TCP_PSH,
        enum_to_string(config->hide_tcp_psh, flag_def, DEF_SIZE(flag_def)));
    fprintf(file, "%s = \"%s\"\n", VAR_HIDE_TCP_FIN,
        enum_to_string(config->hide_tcp_fin, flag_def, DEF_SIZE(flag_def)));
    fprintf(file, "%s = \"%s\"\n", VAR_HIDE_TCP_RST,
        enum_to_string(config->hide_tcp_rst, flag_def, DEF_SIZE(flag_def)));
    fprintf(file, "%s = \"%s\"\n", VAR_HIDE_UDP,
        bool_to_string(config->hide_udp));
    fprintf(file, "%s = \"%s\"\n", VAR_SPLIT_MODE,
        enum_to_string(config->split, split_def, DEF_SIZE(split_def)));
    fprintf(file, "%s = \"%s\"\n", VAR_LOG_LEVEL,
        enum_to_string((config_enum_t)log_get_level(), log_level_def,
        DEF_SIZE(log_level_def)));
    fprintf(file, "%s = \"%s\"\n", VAR_GHOST_MODE,
        enum_to_string(config->ghost, ghost_def, DEF_SIZE(ghost_def)));
    fprintf(file, "%s = \"%s\"\n", VAR_GHOST_CHECK,
        bool_to_string(config->ghost_check));
    fprintf(file, "%s = \"%s\"\n", VAR_GHOST_SET_TTL,
        bool_to_string(config->ghost_set_ttl));
    fprintf(file, "%s = \"%u\"\n", VAR_GHOST_TTL, config->ghost_ttl);
    fprintf(file, "%s = \"%s\"\n", VAR_FRAG_MODE,
        enum_to_string(config->fragment, frag_def, DEF_SIZE(frag_def)));
    fprintf(file, "%s = \"%u\"\n", VAR_TCP_PORT, config->tcp_port);
    fprintf(file, "%s = \"%s\"\n", VAR_TCP_PROTO,
        protocol_get_name(config->tcp_proto));
    fprintf(file, "%s = \"%u\"\n", VAR_UDP_PORT, config->udp_port);
    fprintf(file, "%s = \"%s\"\n", VAR_UDP_PROTO,
        protocol_get_name(config->udp_proto));
    fprintf(file, "%s = \"%u\"\n", VAR_MTU, config->mtu);
    fprintf(file, "%s = \"%s\"\n", VAR_LAUNCH_UI,
        bool_to_string(config->launch_ui));
    fclose(file);

#ifdef WINDOWS
    remove(CONFIG_FILENAME);
#endif
    if (rename(CONFIG_TMP_FILENAME, CONFIG_FILENAME) != 0)
    {
        warning("unable to move temporary configuration file \"%s\" to \"%s\"",
            CONFIG_TMP_FILENAME, CONFIG_FILENAME);
    }
}
开发者ID:ohio813,项目名称:reqrypt,代码行数:77,代码来源:config.c


示例2: main

int
main(int argc, char **argv)
{
	struct stat buf;
	int ret;
	char scratch[BUFSIZ];
	char log[BUFSIZ];
	char olog[BUFSIZ];
	char *scratch_p = scratch;
	char *mytag_p;
	FILE *fp;
	extern char *getenv();
	char *parse();
	int	c;
	extern	char *optarg;
	extern	int optind;
	int i;
	char	*Mytag_p = Mytag;

	/* Get my port monitor tag out of the environment		*/
	if ((mytag_p = getenv("PMTAG")) == NULL) {
		/* no place to write */
		exit(1);
	}
	strcpy(Mytag, mytag_p);

	/* open log file */
	sprintf(log, "%s/%s/%s", ALTDIR, Mytag_p, LOGNAME);
	sprintf(olog, "%s/%s/%s", ALTDIR, Mytag_p, OLOGNAME);
	if (stat(log, &buf) == 0) {
		/* file exists, try and save it but if we can't don't worry */
		unlink(olog);
		rename(log, olog);
	}
	if ((i = open(log, O_WRONLY|O_CREAT|O_APPEND, 0444)) < 0)
		logexit(1, nologfile);
	/* as stated above, the log file should be file descriptor 5 */
	if ((ret = fcntl(i, F_DUPFD, 5)) != 5)
		logexit(1, nologfile);
	Logfp = fdopen(ret, "a+");

	/* Get my port monitor tag out of the environment		*/
	if ((mytag_p = getenv("PMTAG")) == NULL) {
		logexit(1, nopmtag);
	}
	strcpy(Mytag, mytag_p);

	(void) umask(022);
	Readdb = FALSE;

	if (geteuid() != (uid_t) 0) {
		logmessage("Must be root to start listener");
		logexit(1, badstart);
	}

	while ((c = getopt(argc, argv, "m:")) != EOF) 
		switch (c) {
		case 'm':
			Minor_prefix = optarg;
			break;
		default:
			logexit(1, usage);
			break;
		}

	if ((Netspec = argv[optind]) == NULL) {
		logexit(1, usage);
	}
	if ((Netconf = getnetconfigent(Netspec)) == NULL) {
		sprintf(scratch, "no netconfig entry for <%s>", Netspec);
		logmessage(scratch);
		logexit(1, badstart);
	}
	if (!Minor_prefix)
		Minor_prefix = argv[optind];

	if ((int) strlen(Netspec) > PATHSIZE)  {
		logmessage(badnspmsg);
		logexit(1, badstart);
	}

	/* 
	 * SAC will start the listener in the correct directory, so we
	 * don't need to chdir there, as we did in older versions
	 */

	strcpy(Provbuf, "/dev/");
	strcat(Provbuf, Netspec);

	(void) umask(0);

	init_files();		/* open Accept, Sac, Pm, Pass files	*/
	pid_open();		/* create pid file			*/

#ifdef	DEBUGMODE
	sprintf(scratch, "%s/%s/%s", ALTDIR, Mytag, DBGNAME);
	Debugfp = fopen(scratch, "w");
#endif


//.........这里部分代码省略.........
开发者ID:andreiw,项目名称:polaris,代码行数:101,代码来源:listen.c


示例3: _T

void modeltest::editNexus(wxCommandEvent& event)
{
	wxString wxline, nexusFile, nexP, finalB, nexTemp, temp, BICblock, AICblock, HLRTblock;
	char line[2000];
	string p1, p2, p3, sline; int pBpos, sel;
	bool pBlock = false, toIns = true;
	wxArrayString block;
	const wxString choices[] = { _T("hLRTs"), _T("AIC"), _T("BIC")};


	wxFileDialog* dialog = new wxFileDialog (this, "Select NEXUS file to insert PAUP block", "", "", FILETYPES3, wxOPEN, wxDefaultPosition);

    if (dialog->ShowModal() == wxID_OK)
    {
		nexusFile = dialog->GetPath();
		this->outputText->SaveFile("temp.txt");
		ifstream modelOut ("temp.txt");
	
		wxSingleChoiceDialog dialog(this, _T("Select LSET command to parse into NEXUS files"),_T("Please select one"), 3, choices);
		if(dialog.ShowModal() == wxID_OK)
		{
			sel = dialog.GetSelection();
			//if(sel == 1)
			//{
			//	toIns = false;
			//}

			/* getting PAUP blocks from modeltest result file*/
			while(!modelOut.eof())
			{
				modelOut.getline(line, 2000);
				wxline = line;
				if(wxline.Contains("PAUP* Commands Block"))
				{
						modelOut.getline(line, 2000);
						wxline = line;
						do
						{
							if(wxline.Length() >= 1)
							{
								block.Add(wxline+"\n");
							}
							temp += wxline + "\n";
							modelOut.getline(line, 2000);
							wxline = line;
						}while(!wxline.Contains("END"));
						block.Add("END;\n");
						temp += "END;\n";
				}
			}
			HLRTblock = block[0]+block[1]+block[2]+block[3]+block[4]+block[5];
			AICblock = block[6]+block[7]+block[8]+block[9]+block[10]+block[11];
			if(BIC == true)
			{
				BICblock = block[6]+block[7]+block[8]+block[9]+block[10]+block[11];
			}
			modelOut.close();
			/*inserting block on nexus file*/
			string nexustr;
			nexustr = nexusFile;
			ifstream nex(nexustr.c_str());
			nexTemp = nexusFile + "temp";
			ofstream nexT(nexTemp);
			while(!nex.eof())
			{
				nex.getline(line, 2000);
				wxline = line;
				nexT << line << "\n";
			}
			if(sel == 0)
			{
				p1 = HLRTblock;
				nexT << p1 << "\n";
			}
			else if(sel == 1)
			{
				p2 = AICblock;
				nexT << p2 << "\n";
			}
			else if(sel == 2 && BIC == true)
			{
				p3 = BICblock;
				nexT << p3 << "\n";
			}
			else if(sel == 2 && BIC == false)
			{
				wxMessageBox("BIC analysis not available.\nPlease rerun ModelTest with this option enabled");
			}
			nexT << line << "\n";
			nex.close();
			nexT.close();
			remove(nexusFile);
			rename(nexTemp, nexusFile);
		}
	}
}
开发者ID:nuin,项目名称:MrMTgui,代码行数:96,代码来源:mtgui.cpp


示例4: main


//.........这里部分代码省略.........
				if ( 0 == ret ) {

					if ( keep ) {

						/* keep compressed file */

					} else {

						/* remove compressed file */
						ret= unlink( infilename );

						if ( 0 != ret ) {

							fprintf( stderr, "error removing '%s'\n", infilename );
						}
					}

				} else {

					fprintf( stderr, "decompress error for file '%s'\n", infilename );
				} 

				break;

			case MODE_COMPRESS:
			case MODE_DEFAULT:
			default:

				/* compress file */

				/* check for ".z" at the end and refuse compression if found */
				if ( ( 2 < strlen( infilename ) ) &&
				     ( 0 == strcmp( infilename +strlen( infilename ) -2, ".z" ) ) ) {
				
					fprintf( stderr, "ERROR: found '.z' suffix in filename, "
						"file '%s' seems already compressed, skip\n", 
						infilename );

					continue;
				}

				/* add trailing '.z' to output file name */
				if ( strlen( outfilename ) +2 < sizeof( outfilename ) )
					strcat( outfilename, ".z" );

				fprintf( stdout, "compress \"%s\" -> \"%s\"\n", 
					infilename, outfilename );

				ret= compressFile( infilename, outfilename, zlevel, BUFFERSIZE );

				if ( 0 == ret ) {

					if ( keep ) {

						if ( outdir ) {

							/* keep uncompressed file */

						} else {

							/* rename original file */

							snprintf( outfilename, sizeof( outfilename ) -1, "%s.original",
								  infilename );

							ret= rename( infilename, outfilename );
						
							if ( 0 != ret ) {

								fprintf( stderr, "error renaming '%s' to '%s'\n", 
									 infilename, outfilename );

							}

						}

					} else {

						/* remove uncompressed */

						ret= unlink( infilename );

						if ( 0 != ret ) {

							fprintf( stderr, "error removing '%s'\n", infilename );
						}
					}

				} else {

					fprintf( stderr, "compress error for file '%s'\n", infilename );
				}

				break;
			}
		}
	}

	return 0;
}
开发者ID:315234,项目名称:OpenFOAM-2.2.x-OSX,代码行数:101,代码来源:otfcompress.c


示例5: trunk_binlog_merge_file

static int trunk_binlog_merge_file(int old_fd)
{
	int result;
	int tmp_fd;
	int bytes;
	char binlog_filename[MAX_PATH_SIZE];
	char tmp_filename[MAX_PATH_SIZE];
	char buff[64 * 1024];

	get_trunk_binlog_filename(binlog_filename);
	sprintf(tmp_filename, "%s.tmp", binlog_filename);
	tmp_fd = open(tmp_filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
	if (tmp_fd < 0)
	{
		result = errno != 0 ? errno : EACCES;
		logError("file: "__FILE__", line: %d, " \
			"open file \"%s\" fail, " \
			"errno: %d, error info: %s", \
			__LINE__, tmp_filename, result, STRERROR(result));
		return result;
	}

	while ((bytes=fc_safe_read(old_fd, buff, sizeof(buff))) > 0)
	{
		if (fc_safe_write(tmp_fd, buff, bytes) != bytes)
		{
			result = errno != 0 ? errno : EACCES;
			logError("file: "__FILE__", line: %d, " \
				"write to file \"%s\" fail, " \
				"errno: %d, error info: %s", \
				__LINE__, tmp_filename,
				result, STRERROR(result));
			close(tmp_fd);
			return result;
		}
	}

	if (access(binlog_filename, F_OK) == 0)
	{
		int binlog_fd;
		if ((binlog_fd=trunk_binlog_open_read(binlog_filename,
			false)) < 0)
		{
			close(tmp_fd);
			return errno != 0 ? errno : EPERM;
		}

		while ((bytes=fc_safe_read(binlog_fd, buff, sizeof(buff))) > 0)
		{
			if (fc_safe_write(tmp_fd, buff, bytes) != bytes)
			{
				result = errno != 0 ? errno : EACCES;
				logError("file: "__FILE__", line: %d, " \
					"write to file \"%s\" fail, " \
					"errno: %d, error info: %s", \
					__LINE__, tmp_filename,
					result, STRERROR(result));
				close(tmp_fd);
				close(binlog_fd);
				return result;
			}
		}
		close(binlog_fd);
	}

	if (fsync(tmp_fd) != 0)
	{
		result = errno != 0 ? errno : EIO;
		logError("file: "__FILE__", line: %d, " \
			"sync file \"%s\" fail, " \
			"errno: %d, error info: %s",  \
			__LINE__, tmp_filename, \
			errno, STRERROR(errno));
		close(tmp_fd);
		return result;
	}
	close(tmp_fd);

	if (rename(tmp_filename, binlog_filename) != 0)
	{
		result = errno != 0 ? errno : EPERM;
		logError("file: "__FILE__", line: %d, " \
			"rename %s to %s fail, " \
			"errno: %d, error info: %s",
			__LINE__, tmp_filename, binlog_filename,
			result, STRERROR(result));
		return result;
	}

	return 0;
}
开发者ID:didiwuliu,项目名称:fastdfs,代码行数:91,代码来源:trunk_sync.c


示例6: trunk_reader_init

int trunk_reader_init(FDFSStorageBrief *pStorage, TrunkBinLogReader *pReader)
{
	char full_filename[MAX_PATH_SIZE];
	IniContext iniContext;
	int result;
	int64_t saved_binlog_offset;
	bool bFileExist;

	saved_binlog_offset = pReader->binlog_offset;

	memset(pReader, 0, sizeof(TrunkBinLogReader));
	pReader->mark_fd = -1;
	pReader->binlog_fd = -1;

	pReader->binlog_buff.buffer = (char *)malloc( \
				TRUNK_BINLOG_BUFFER_SIZE);
	if (pReader->binlog_buff.buffer == NULL)
	{
		logError("file: "__FILE__", line: %d, " \
			"malloc %d bytes fail, " \
			"errno: %d, error info: %s", \
			__LINE__, TRUNK_BINLOG_BUFFER_SIZE, \
			errno, STRERROR(errno));
		return errno != 0 ? errno : ENOMEM;
	}
	pReader->binlog_buff.current = pReader->binlog_buff.buffer;

	if (pStorage == NULL)
	{
		strcpy(pReader->storage_id, "0.0.0.0");
	}
	else
	{
		strcpy(pReader->storage_id, pStorage->id);
	}
	trunk_mark_filename_by_reader(pReader, full_filename);

	if (pStorage == NULL)
	{
		bFileExist = false;
		pReader->binlog_offset = saved_binlog_offset;
	}
	else
	{
		bFileExist = fileExists(full_filename);
		if (!bFileExist && (g_use_storage_id && pStorage != NULL))
		{
			char old_mark_filename[MAX_PATH_SIZE];
			trunk_get_mark_filename_by_ip_and_port( \
				pStorage->ip_addr, g_server_port, \
				old_mark_filename, sizeof(old_mark_filename));
			if (fileExists(old_mark_filename))
			{
				if (rename(old_mark_filename, full_filename)!=0)
				{
					logError("file: "__FILE__", line: %d, "\
						"rename file %s to %s fail" \
						", errno: %d, error info: %s", \
						__LINE__, old_mark_filename, \
						full_filename, errno, \
						STRERROR(errno));
					return errno != 0 ? errno : EACCES;
				}
				bFileExist = true;
			}
		}
	}

	if (bFileExist)
	{
		memset(&iniContext, 0, sizeof(IniContext));
		if ((result=iniLoadFromFile(full_filename, &iniContext)) \
			 != 0)
		{
			logError("file: "__FILE__", line: %d, " \
				"load from mark file \"%s\" fail, " \
				"error code: %d", \
				__LINE__, full_filename, result);
			return result;
		}

		if (iniContext.global.count < 1)
		{
			iniFreeContext(&iniContext);
			logError("file: "__FILE__", line: %d, " \
				"in mark file \"%s\", item count: %d < 7", \
				__LINE__, full_filename, iniContext.global.count);
			return ENOENT;
		}

		pReader->binlog_offset = iniGetInt64Value(NULL, \
					MARK_ITEM_BINLOG_FILE_OFFSET, \
					&iniContext, -1);
		if (pReader->binlog_offset < 0)
		{
			iniFreeContext(&iniContext);
			logError("file: "__FILE__", line: %d, " \
				"in mark file \"%s\", binlog_offset: "\
				"%"PRId64" < 0", \
				__LINE__, full_filename, \
//.........这里部分代码省略.........
开发者ID:didiwuliu,项目名称:fastdfs,代码行数:101,代码来源:trunk_sync.c


示例7: os_rename

static int os_rename (lua_State *L) {
  const char *fromname = luaL_checkstring(L, 1);
  const char *toname = luaL_checkstring(L, 2);
  return luaL_fileresult(L, rename(fromname, toname) == 0, fromname);
}
开发者ID:alucard-dracula,项目名称:yggdrasil,代码行数:5,代码来源:loslib.c


示例8: wrename

int wrename(const OsPath& pathnameOld, const OsPath& pathnameNew)
{
	return rename(OsString(pathnameOld).c_str(), OsString(pathnameNew).c_str());
}
开发者ID:2asoft,项目名称:0ad,代码行数:4,代码来源:ufilesystem.cpp


示例9: main

int
main (int argc, char **argv)
{
  const char *name, *error;
  char *renamed;
  aiger *aiger;
  int i, res;

  name = 0;
  for (i = 1; i < argc; i++)
    {
      if (!strcmp (argv[i], "-h"))
	{
	  fprintf (stderr, "usage: aigstrip [-h][<file>]\n");
	  return 0;
	}
      else if (argv[i][0] == '-')
	{
	  fprintf (stderr, "*** [aigstrip] invalid option '%s'\n", argv[i]);
	  return 1;
	}
      else if (name)
	{
	  fprintf (stderr, "*** [aigstrip] multiple files\n");
	  return 1;
	}
      else
	name = argv[i];
    }

  res = 0;

  aiger = aiger_init ();
  if (!name) 
    {
      if((error = aiger_read_from_file (aiger, stdin))) goto PARSE_ERROR;
      (void) aiger_strip_symbols_and_comments (aiger);
      if (!aiger_write_to_file (aiger,
             (isatty (1) ? aiger_ascii_mode : aiger_binary_mode), stdout))
	{
	  fprintf (stderr, "*** [aigstrip] write error\n");
	  res = 1;
	}
    }
  else if ((error = aiger_open_and_read_from_file (aiger, name)))
    {
PARSE_ERROR:
      fprintf (stderr, "*** [aigstrip] read error: %s\n", error);
      res = 1;
    }
  else 
    {
      (void) aiger_strip_symbols_and_comments (aiger);
      renamed = malloc (strlen (name) + 2);
      sprintf (renamed, "%s~", name);

      if (rename (name, renamed))
	{
	  fprintf (stderr, "*** [aigstrip] failed to rename '%s'\n", name);
	  res = 1;
	}
      else if (aiger_open_and_write_to_file (aiger, name))
	{
	  if (unlink (renamed))
	    {
	      fprintf (stderr,
		       "*** [aigstrip] failed to remove '%s'\n", renamed);

	      res = 0;		/* !!! */
	    }
	}
      else
	{

	  fprintf (stderr, "*** [aigstrip] failed to write '%s'\n", name);
	  res = 1;

	  if (rename (renamed, name))
	    fprintf (stderr, "*** [aigstrip] backup in '%s'\n", renamed);
	  else
	    fprintf (stderr, "*** [aigstrip] original file restored\n");
	}

      free (renamed);
    }

  aiger_reset (aiger);

  return res;
}
开发者ID:johnyf,项目名称:aiger_tools,代码行数:90,代码来源:aigstrip.c


示例10: redirect

void redirect (const char *line, const char *makefile)
{
    struct stat st;
    FILE *fdin, *fdout;
    char backup[BUFSIZ], buf[BUFSIZ];
    bool found = false;
    int len;

    /* if makefile is "-" then let it pour onto stdout. */
    if (makefile && *makefile == '-' && *(makefile + 1) == '\0')
    {
        puts (line);
        return;
    }

    /* use a default makefile is not specified. */
    if (!makefile)
    {
        if (stat ("Makefile", &st) == 0)
            makefile = "Makefile";
        else if (stat ("makefile", &st) == 0)
            makefile = "makefile";
        else
            fatalerr ("[mM]akefile is not present\n");
    }
    else
        if (stat (makefile, &st))
            st.st_mode = 0640;

    if ((fdin = fopen (makefile, "r")) == NULL)
    {
        /* Try to create file if it does not exist */
        if (opt_create)
        {
            fdin = fopen (makefile, "w");
            if (fdin)
            {
                fclose (fdin);
                fdin = fopen (makefile, "r");
            }
        }
        if (!fdin)
            fatalerr ("cannot open \"%s\"\n", makefile);
    }

#if defined (__DJGPP__)
    // DOS cannot handle long filenames
    {
        char *src = makefile;
        char *dst = backup;
        while (*src && (*src != '.'))
            *dst++ = *src++;
        strcpy (dst, ".bak");
    }
#else
    sprintf (backup, "%s.bak", makefile);
#endif
    unlink (backup);
#if defined(WIN32) || defined(__EMX__) || defined (__DJGPP__)
    fclose (fdin);
#endif
    if (rename (makefile, backup) < 0)
        fatalerr ("cannot rename %s to %s\n", makefile, backup);
#if defined(WIN32) || defined(__EMX__) || defined (__DJGPP__)
    if ((fdin = fopen (backup, "r")) == NULL)
        fatalerr ("cannot open \"%s\"\n", backup);
#endif
    if ((fdout = freopen (makefile, "w", stdout)) == NULL)
        fatalerr ("cannot open \"%s\"\n", backup);
    len = strlen (line);
    while (!found && fgets (buf, BUFSIZ, fdin))
    {
        if (*buf == '#' && strncmp (line, buf, len) == 0)
            found = true;
        fputs (buf, fdout);
    }
    if (!found)
    {
        if (opt_verbose)
            warning ("Adding new delimiting line \"%s\" and dependencies...\n",
                     line);
        puts (line);	/* same as fputs(fdout); but with newline */
    }
    else if (opt_append)
    {
        while (fgets (buf, BUFSIZ, fdin))
        {
            fputs (buf, fdout);
        }
    }
    fflush (fdout);
#if defined(USGISH) || defined(_SEQUENT_) || defined(USE_CHMOD)
    chmod (makefile, st.st_mode);
#else
    fchmod (fileno (fdout), st.st_mode);
#endif /* USGISH */

    fclose (fdin);
    if (!opt_backup)
        unlink (backup);
//.........这里部分代码省略.........
开发者ID:MWisBest,项目名称:android_external_Focal,代码行数:101,代码来源:main.cpp


示例11: omrfile_move

int32_t
omrfile_move(struct OMRPortLibrary *portLibrary, const char *pathExist, const char *pathNew)
{
	return rename(pathExist, pathNew);
}
开发者ID:ChengJin01,项目名称:omr,代码行数:5,代码来源:omrfile.c


示例12: main


//.........这里部分代码省略.........
                                                                        system("cls");
                                                                        }

                                                                       gotoxy(25,16);

                                                                        printf("Press any key to Return to Main Menu");
                                                                               getch();
                                                                               break;
                  case 3:
                       //Delete entry
                                                system("cls");
                                                FILE *fn;
                                                  gotoxy(25,10);
                                                  printf("Enter roll no.:\t");
                                                  scanf("%d",&rol);

                                                  fp=fopen("hostel_data.txt","r");
                                                  fn=fopen("hostel_data2.txt","w");
                                                   while(another=='y'||another=='Y')
                                   {

                                                  while(fscanf(fp,"%d%s%s%s%d%d%d%d",&eh[i].roll,eh[i].name,eh[i].deptt,eh[i].permntadd,&eh[i].roomno,&eh[i].ac.messchrges,&eh[i].ac.fine,&eh[i].ac.total)!=EOF)
                                                  { if(eh[i].roll==rol)
                                                  flag=1;


                                                  if(eh[i].roll!=rol)
                                                  {fprintf(fn,"%d\t%s\t%s\t%s\t%d\t%d\t%d\t%d\n",eh[i].roll,eh[i].name,eh[i].deptt,eh[i].permntadd,eh[i].roomno,eh[i].ac.messchrges,eh[i].ac.fine,eh[i].ac.total);
                                                  }
                                                                        }
                                                                        fclose(  fp);
                                                                            fclose(  fn);
                                                                            remove(  "hostel_data.txt");
                                                                            rename( "hostel_data2.txt", "hostel_data.txt");
                                                                      gotoxy(25,12);
                                                                      if(flag==1)
                                                                       printf("Entry Successfully Deleted");
                                                                       if(flag==0)
                                                                       printf("Not in Record!");
                                                                       gotoxy(25,14);
                                                                      printf("Want to Delete Another Record(press y/n):\t");
                                                                       fflush(stdin);
                                                                        scanf("%c",&another);
                                                                        getch();
                                                                        system("cls");
                                                                        }
                                                                        gotoxy(25,16);
                                                                       printf("Press any key to Return to Main Menu");
                                                                        getch();
                                                                       break;





                  case 4:
                       //modify entry
                       system("cls");
                       FILE *f;
                       gotoxy(25,10);
                       printf("Enter Roll number whose Record is to be modified\t");
                       scanf("%d",&rol);
                       fp=fopen("hostel_data.txt","r");
                       f=fopen("hostel_data3.txt","w");

                        while(another=='y'||another=='Y')
开发者ID:Prinkamodi,项目名称:Hostel-Management-System,代码行数:67,代码来源:main.c


示例13: dload_printf_to_file

/*lint -e528*/
static int dload_printf_to_file(const char *path, int tv_sec, int tv_usec, const char *buf)
{
    FILE    *pFile = NULL;
    int     file_length = 0;
    char    filea_name[DLOAD_LOGREC_PATH_LENGTH] = {0};
    char    fileb_name[DLOAD_LOGREC_PATH_LENGTH] = {0};
    int     ret = 0;
    int     status = 0;

    ret = access(path, F_OK);
    if(ret)
    {
        /* 目录不存在,则创建目录 */
        status = mkdir(path, S_IRWXU);
        if(-1 == status)
        {
            printf("[DLOAD LOGREC] mkdir %s error.\n", path, strerror(errno));
            return DLOAD_ERR;
        }
    }

    /*获取file A长度*/
    /*lint -e119*/
    snprintf(filea_name, DLOAD_LOGREC_PATH_LENGTH, "%s%s", path, DLOAD_LOGREC_FILENAME_A);
    /*lint +e119*/
    pFile = fopen(filea_name, "a+");
    if (NULL == pFile)
    {
        printf("[DLOAD LOGREC] fopen %s, %s\n", filea_name, strerror(errno));
        return DLOAD_ERR;
    }

    ret = fseek(pFile, 0, SEEK_END);
    if(0 != ret)
    {
        fclose(pFile);

        printf("[DLOAD LOGREC] fseek %s, %s\n", filea_name, strerror(errno));
        return DLOAD_ERR;       
    }
    
    file_length = ftell(pFile);
    if(0 > file_length)
    {
        fclose(pFile);

        printf("[DLOAD LOGREC] Get length %s, %s\n", filea_name, strerror(errno));
        return DLOAD_ERR;
    }

    /*如果超长: A->B, new A*/
    if (DLOAD_LOGREC_MAX_FILESIZE <= file_length)
    {
        fclose(pFile);
        /*lint -e119*/
        snprintf(fileb_name, DLOAD_LOGREC_PATH_LENGTH, "%s%s", path, DLOAD_LOGREC_FILENAME_B);
        /*lint +e119*/
        ret = rename(filea_name, fileb_name);
        if (0 != ret)
        {
            printf("[DLOAD LOGREC] Rename %s to %s, %s\n", filea_name, fileb_name, strerror(errno));
            return DLOAD_ERR;
        }

        pFile = NULL;
        pFile = fopen(filea_name, "a+");
        if (NULL == pFile)
        {
            printf("[DLOAD LOGREC] Open %s, %s\n", filea_name, strerror(errno));
            return DLOAD_ERR;
        }
    }

    ret = fprintf(pFile, "[%d.%d]", tv_sec, tv_usec);
    if (0 > ret)
    {
        fclose(pFile);
        printf("[DLOAD LOGREC] fprintf %s, %s\n", filea_name, strerror(errno));
        return DLOAD_ERR;
    }

    ret = fprintf(pFile, "%s", buf);
    if (0 > ret)
    {
        fclose(pFile);

        printf("[DLOAD LOGREC] fvprintf %s, %s\n", filea_name, strerror(errno));
        return DLOAD_ERR;
    }

    fclose(pFile);
    return DLOAD_OK;
}
开发者ID:samm-git,项目名称:e3372h-vendor-src,代码行数:94,代码来源:dload_debug.c


示例14: main

main(int argc, char **argv)
{
	struct stat sb;
	int errs;

	if (argc < 3) {
		usage();
	}

	/*
	 * If moving a bunch of files to a directory, last element
	 * has to be a directory.
	 */
	if (stat(argv[argc-1], &sb) < 0) {
		/*
		 * a, b, c -> d		But d doesn't exist
		 */
		if (argc > 3) {
			fprintf(stderr, "Last argument should be dir: %s\n",
				argv[argc-1]);
			exit(1);
		}

		/*
		 * a -> b
		 */
		if (rename(argv[1], argv[2]) < 0) {
			perror(argv[2]);
			exit(1);
		}
		exit(0);
	}

	/*
	 * If dest is a directory, move each into it
	 */
	errs = 0;
	if ((sb.st_mode & S_IFMT) == S_IFDIR) {
		int x, len;
		char *base;

		argc -= 1;
		base = argv[argc];
		len = strlen(base)+1;
		for (x = 1; x < argc; ++x) {
			char *dest;

			dest = malloc(len + strlen(argv[x]) + 1);
			sprintf(dest, "%s/%s", base, argv[x]);
			if (rename(argv[x], dest) < 0) {
				perror(dest);
				errs += 1;
			}
		}
	} else {
		/*
		 * Existing dest--overwrite if a -> b, otherwise error
		 */
		if (argc != 3) {
			fprintf(stderr, "Last argument should be dir: %s\n",
				argv[argc-1]);
			exit(1);
		}
		unlink(argv[2]);
		if (rename(argv[1], argv[2]) < 0) {
			perror(argv[2]);
			errs = 1;
		}
	}
	return(errs ? 1 : 0);
}
开发者ID:JamesLinus,项目名称:vsta,代码行数:71,代码来源:mv.c


示例15: test_rename

void test_rename(char *workdir) {
    char file1[1024], file2[1024], link[1024],
         subdir[1024], newdir[1024];
    struct stat sb1, sb2;
    int fd;

    printf("testing rename\n");

    sprintf(file1, "%s/file1", workdir);
    sprintf(file2, "%s/file2", workdir);

    /* test stat first.. since we need it to test rename */
    my_stat(file1, &sb1);

    /* Not much to look at, really..  how about making sure that
       the modification time of the file is not in the future.
       allow ten seconds of slack */
    if (sb1.st_mtime > time(NULL) + 10) {
        printf("Modification time of %s is in the future!\n",
               file1);
        exit(1);
    }

    my_rename(file1, file2);

    /* try repeat */
    if (!rename(file1, file2)) {
        printf("repeat rename(%s,%s) worked.. but it shouldn't have\n",
               file1, file2);
        exit(1);
    }


    /* inode number of file2 should be the same as it was for file1 */
    verify_inum(file2, &sb1);


    /* rename back */
    my_rename(file2, file1);

    verify_inum(file1, &sb1);

    /* Make a subdir, which will be renamed */
    sprintf(subdir, "%s/rename_this_dir", workdir);

    my_mkdir(subdir);
    my_stat(subdir, &sb2);

    /* Test moving a file into a subdir */
    sprintf(file2, "%s/file1", subdir);
    my_rename(file1, file2);
    verify_inum(file2, &sb1);

    /* Add in a hard link to spice things up */
    sprintf(link, "%s/link", subdir);
    my_link(file2, link);

    sprintf(newdir, "%s/newdirname", workdir);
    my_rename(subdir, newdir);
    verify_inum(newdir, &sb2);
    sprintf(file2, "%s/file1", newdir);
    verify_inum(file2, &sb1);
    sprintf(link, "%s/newdirname/link", workdir);
    verify_inum(link, &sb1);

    /* Test moving up in the tree */
    my_rename(file2,file1);
    verify_inum(file1, &sb1);

    my_unlink(link);

    my_rmdir(newdir);

}
开发者ID:john-peterson,项目名称:nfs,代码行数:74,代码来源:testnfs.c


示例16: trunk_binlog_compress_apply

int trunk_binlog_compress_apply()
{
	int result;
	char binlog_filename[MAX_PATH_SIZE];
	char rollback_filename[MAX_PATH_SIZE];

	get_trunk_binlog_filename(binlog_filename);
	if (get_trunk_rollback_filename(rollback_filename) == NULL)
	{
		logError("file: "__FILE__", line: %d, " \
			"filename: %s is too long",
			__LINE__, binlog_filename);
		return ENAMETOOLONG;
	}

	if (trunk_binlog_fd < 0)
	{
		if (access(binlog_filename, F_OK) == 0)
		{
			if (rename(binlog_filename, rollback_filename) != 0)
			{
				result = errno != 0 ? errno : EIO;
				logError("file: "__FILE__", line: %d, " \
					"rename %s to %s fail, " \
					"errno: %d, error info: %s",
					__LINE__, binlog_filename,
					rollback_filename, result,
					STRERROR(result));
				return result;
			}
		}
		else if (errno != ENOENT)
		{
			result = errno != 0 ? errno : EIO;
			logError("file: "__FILE__", line: %d, " \
				"call access %s fail, " \
				"errno: %d, error info: %s",
				__LINE__, binlog_filename,
				result, STRERROR(result));
			return result;
		}

		return 0;
	}

	if ((result=trunk_binlog_close_writer(true)) != 0)
	{
		return result;
	}

	if (rename(binlog_filename, rollback_filename) != 0)
	{
		result = errno != 0 ? errno : EIO;
		logError("file: "__FILE__", line: %d, " \
			"rename %s to %s fail, " \
			"errno: %d, error info: %s",
			__LINE__, binlog_filename, rollback_filename,
			result, STRERROR(result));
		return result;
	}

	if ((result=trunk_binlog_open_writer(binlog_filename)) != 0)
	{
		rename(rollback_filename, binlog_filename);  //rollback
		return result;
	}

	return 0;
}
开发者ID:didiwuliu,项目名称:fastdfs,代码行数:69,代码来源:trunk_sync.c


示例17: TitleBrowser


//.........这里部分代码省略.........
						if (!error) {
						    gprintf("\nno error yet");

							network_read((u8*) &filename, 100);
							gprintf("\nfilename: %s",filename);

							// Do we need to unzip this thing?
							if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4) {
							    gprintf("\nusing newer wiiload version");

								if (uncfilesize != 0) { // if uncfilesize == 0, it's not compressed
								    gprintf("\ntrying to uncompress");
									// It's compressed, uncompress
									u8 *unc = (u8 *) malloc(uncfilesize);
									uLongf f = uncfilesize;
									error = uncompress(unc, &f, temp, infilesize) != Z_OK;
									uncfilesize = f;

									free(temp);
									temp = unc;
								}
							}

							if (!error) {
								sprintf(tmptxt,"%s",filename);
								//if we got a wad
								if (strcasestr(tmptxt,".wad")) {
								    FILE *file = fopen(filepath, "wb");
								    fwrite(temp, 1, (uncfilesize>0?uncfilesize:infilesize), file);
								    fclose(file);

								    sprintf(tmptxt,"%s/wad/%s",bootDevice,filename);
								    if (checkfile(tmptxt))remove(tmptxt);
								    rename(filepath, tmptxt);

								    //check and make sure the wad we just saved is the correct size
								    u32 lSize;
								    file = fopen(tmptxt, "rb");

								    // obtain file size:
								    fseek (file , 0 , SEEK_END);
								    lSize = ftell (file);

								    rewind (file);
								    if (lSize==(uncfilesize>0?uncfilesize:infilesize)) {
									gprintf("\nsize is ok");
									int pick = WindowPrompt(tr(" Wad Saved as:"), tmptxt, tr("Install"),tr("Uninstall"),tr("Cancel"));
									//install or uninstall it
									if (pick==1)
										{
											HaltGui();
											w.Remove(&titleTxt);
											w.Remove(&cancelBtn);
											w.Remove(&wifiBtn);
											w.Remove(&optionBrowser3);
											ResumeGui();

											Wad_Install(file);

											HaltGui();
											w.Append(&titleTxt);
											w.Append(&cancelBtn);
											w.Append(&wifiBtn);
											w.Append(&optionBrowser3);
											ResumeGui();
开发者ID:gnils,项目名称:usbloader-gx,代码行数:66,代码来源:TitleBrowser.cpp


示例18: trunk_binlog_compress_rollback

int trunk_binlog_compress_rollback()
{
	int result;
	int rollback_fd;
	char binlog_filename[MAX_PATH_SIZE];
	char rollback_filename[MAX_PATH_SIZE];
	struct stat fs;

	get_trunk_binlog_filename(binlog_filename);
	get_trunk_rollback_filename(rollback_filename);
	if (trunk_binlog_fd < 0)
	{
		if (access(rollback_filename, F_OK) == 0)
		{
			if (rename(rollback_filename, binlog_filename) != 0)
			{
				result = errno != 0 ? errno : EPERM;
				logError("file: "__FILE__", line: %d, "\
					"rename %s to %s fail, " \
					"errno: %d, error info: %s",
					__LINE__, rollback_filename,
					binlog_filename, result,
					STRERROR(result));
				return result;
			}
		}

		return 0;
	}

	if (stat(rollback_filename, &fs) != 0)
	{
		result = errno != 0 ? errno : ENOENT;
		if (result == ENOENT)
		{
			return 0;
		}
		logError("file: "__FILE__", line: %d, " \
			"stat file %s fail, errno: %d, error info: %s",
			__LINE__, rollback_filename,
			result, STRERROR(result));
		return result;
	}

	if (fs.st_size == 0)
	{
		unlink(rollback_filename);  //delete zero file directly
		return 0;
	}

	if ((result=trunk_binlog_close_writer(true)) != 0)
	{
		return result;
	}

	if ((rollback_fd=trunk_binlog_open_read(rollback_filename,
		false)) < 0)
	{
		return errno != 0 ? errno : ENOENT;
	}

	result = trunk_binlog_merge_file(rollback_fd);
	close(rollback_fd);
	if (result == 0)
	{
		if (unlink(rollback_filename) != 0)
		{
			result = errno != 0 ? errno : EPERM;
			logWarning("file: "__FILE__", line: %d, " \
				"unlink %s fail, " \
				"errno: %d, error info: %s",
				__LINE__, rollback_filename,
				result, STRERROR(result));
		}

		return trunk_binlog_open_writer(binlog_filename);
	}
	else
	{
		trunk_binlog_open_writer(binlog_filename);
		return result;
	}
}
开发者ID:didiwuliu,项目名称:fastdfs,代码行数:83,代码来源:trunk_sync.c


示例19: isc_movefile

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rend函数代码示例发布时间:2022-05-30
下一篇:
C++ ren函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap