g_histo.c

来自「Non-Networked File System在几个非网络的(或慢网络的)U」· C语言 代码 · 共 113 行

C
113
字号
/*    NNFS: Non-Networked File System. *    Copyright (C) 1995-1998  Thierry EXCOFFIER (exco@ligim.univ-lyon1.fr) * *    This program is free software; you can redistribute it and/or modify *    it under the terms of the GNU General Public License as published by *    the Free Software Foundation; either version 2 of the License, or *    (at your option) any later version. * *    This program is distributed in the hope that it will be useful, *    but WITHOUT ANY WARRANTY; without even the implied warranty of *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *    GNU General Public License for more details. * *    You should have received a copy of the GNU General Public License *    along with this program; if not, write to the Free Software *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "g_debug.h"#include "g_malloc.h"#include "g_copy.h"#include "g_nnfs.h"#include "g_openp.h"#include "g_secure.h"#if HAVE_ERRNO_H#include <errno.h>#endif#if HAVE_STRING_H#include <string.h>#endif/* * Secure move */g_Boolean G_FUNCTION(g_Rename,(const char *old, const char *new))g_Boolean err ;G_PF("%s is renamed as %s\n",old, new) ;err = g_False ;if ( g_Open_Path(new) )	{	(void)remove(old) ;	G_RETURN(g_True) ;	}if ( rename(old,new) )  {  if ( errno != ENOENT )    {      if ( errno!=EXDEV )	{	  g_Printf("Error renaming %s to %s\n",old, new) ;	  perror("rename") ;	}      err = g_Copy_File(old, new) ;      (void)remove(old) ;    }  }G_RETURN(err) ;}char * G_FUNCTION(g_History_Dir,(const char* nnfs, const char* format))char *d ;time_t t ;G_PF("Fomart = %s\n",format) ;G_MALLOC(d,strlen(nnfs)+1+2*strlen(format)+1) ;sprintf(d,"%s%c", nnfs, G_CHAR_SEPARATOR) ;time(&t) ;#if HAVE_STRFTIMEstrftime( d+strlen(d), 2*strlen(format)+1, format, localtime(&t) ) ;#elsesprintf( d+strlen(d), "%d", t) ;#endifG_RETURN(d) ;}/* * */g_Boolean G_FUNCTION(g_Historize,(g_NNFS *nnfs, g_File_Info *f))char *new_name ;g_Boolean err ;                        G_PF("4444\n") ;fflush(stderr) ;err = g_False ;if ( f->to_historize ){  /* 06/08/97 +2 */  new_name = g_Formatted_Strings("%" G_STRING_SEPARATOR "%",				 nnfs->config.history,				 strncmp(nnfs->state.name,"./",2)				 ? nnfs->state.name : nnfs->state.name+2) ;  G_PF("new_name=%x (%s)\n", (int)new_name, new_name) ;  err = g_Rename( nnfs->state.name, new_name) ;  G_PF("new_name=%x (%s)\n", (int)new_name, new_name) ;  g_Free(new_name) ;  f->to_historize = g_False ;}else  (void)remove(nnfs->state.name) ;G_RETURN(err) ;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?