Move set_date() to a separate file
This commit is contained in:
parent
79594ca992
commit
d7a1c2e182
11 changed files with 101 additions and 37 deletions
|
@ -22,7 +22,7 @@ fs_H = analyse.h bfs.h bsd.h cramfs.h exfat.h fat.h fatx.h ext2.h jfs_superblo
|
|||
testdisk_ncurses_C = addpart.c adv.c askloc.c chgtype.c chgtypen.c dimage.c dirn.c dirpart.c diskacc.c diskcapa.c edit.c ext2_sb.c ext2_sbn.c fat1x.c fat32.c fat_adv.c fat_cluster.c fatn.c geometry.c godmode.c hiddenn.c intrface.c intrfn.c nodisk.c ntfs_adv.c ntfs_fix.c ntfs_udl.c parti386n.c partgptn.c partmacn.c partsunn.c partxboxn.c tanalyse.c tbanner.c tdelete.c tdiskop.c tdisksel.c testdisk.c thfs.c tload.c tlog.c tmbrcode.c tntfs.c toptions.c tpartwr.c
|
||||
testdisk_ncurses_H = addpart.h adv.h askloc.h chgtype.h chgtypen.h dimage.h dirn.h dirpart.h diskacc.h diskcapa.h edit.h ext2_sb.h ext2_sbn.h fat1x.h fat32.h fat_adv.h fat_cluster.h fatn.h geometry.h godmode.h hiddenn.h intrface.h intrfn.h nodisk.h ntfs_udl.h partgptn.h parti386n.h partmacn.h partsunn.h partxboxn.h tanalyse.h tdelete.h tdiskop.h tdisksel.h thfs.h tload.h tlog.h tmbrcode.h tntfs.h toptions.h tpartwr.h
|
||||
|
||||
testdisk_SOURCES = $(base_C) $(base_H) $(fs_C) $(fs_H) $(testdisk_ncurses_C) $(testdisk_ncurses_H) dir.c dir.h ext2_dir.c ext2_dir.h ext2_inc.h fat_dir.c fat_dir.h ntfs_dir.c ntfs_dir.h ntfs_inc.h partgptw.c rfs_dir.c rfs_dir.h $(ICON_TESTDISK) next.c next.h
|
||||
testdisk_SOURCES = $(base_C) $(base_H) $(fs_C) $(fs_H) $(testdisk_ncurses_C) $(testdisk_ncurses_H) dir.c dir.h ext2_dir.c ext2_dir.h ext2_inc.h fat_dir.c fat_dir.h ntfs_dir.c ntfs_dir.h ntfs_inc.h partgptw.c rfs_dir.c rfs_dir.h setdate.c setdate.h $(ICON_TESTDISK) next.c next.h
|
||||
|
||||
file_C = filegen.c \
|
||||
file_list.c \
|
||||
|
@ -212,9 +212,9 @@ file_C = filegen.c \
|
|||
|
||||
file_H = list.h file_jpg.h file_tar.h file_sp3.h file_tiff.h filegen.h pe.h ole.h ext2.h
|
||||
|
||||
photorec_C = photorec.c phcfg.c dir.c ext2grp.c ext2_dir.c ext2p.c fat_dir.c fatp.c file_found.c list.c ntfs_dir.c ntfsp.c sessionp.c
|
||||
photorec_C = photorec.c phcfg.c dir.c ext2grp.c ext2_dir.c ext2p.c fat_dir.c fatp.c file_found.c list.c ntfs_dir.c ntfsp.c sessionp.c setdate.c
|
||||
|
||||
photorec_H = photorec.h phcfg.h dir.h ext2grp.h ext2p.h ext2_dir.h ext2_inc.h fat_dir.h fatp.h file_found.h memmem.h ntfs_dir.h ntfsp.h ntfs_inc.h sessionp.h
|
||||
photorec_H = photorec.h phcfg.h dir.h ext2grp.h ext2p.h ext2_dir.h ext2_inc.h fat_dir.h fatp.h file_found.h memmem.h ntfs_dir.h ntfsp.h ntfs_inc.h sessionp.h setdate.h
|
||||
|
||||
photorec_ncurses_C = addpart.c askloc.c chgtype.c chgtypen.c fat_cluster.c fat_unformat.c geometry.c hiddenn.c intrfn.c nodisk.c parti386n.c partgptn.c partmacn.c partsunn.c partxboxn.c pbanner.c pblocksize.c pdisksel.c pfree_whole.c phbf.c phbs.c phnc.c phrecn.c ppartsel.c
|
||||
photorec_ncurses_H = addpart.h askloc.h chgtype.h chgtypen.h fat_cluster.h fat_unformat.h geometry.h hiddenn.h intrfn.h nodisk.h parti386n.h partgptn.h partmacn.h partsunn.h partxboxn.h pblocksize.h pdisksel.h pfree_whole.h pnext.h phbf.h phbs.h phnc.h phrecn.h ppartsel.h
|
||||
|
@ -223,7 +223,7 @@ photorec_SOURCES = phmain.c $(photorec_C) $(photorec_H) $(photorec_ncurses_C) $(
|
|||
|
||||
qphotorec_SOURCES = qmainrec.cpp qphotorec.cpp qphotorec.h chgtype.c chgtype.h $(photorec_C) $(photorec_H) $(file_C) $(file_H) $(base_C) $(base_H) partgptro.c $(fs_C) $(fs_H) $(ICON_PHOTOREC)
|
||||
|
||||
fidentify_SOURCES = fidentify.c common.c common.h phcfg.c phcfg.h $(file_C) $(file_H) log.c log.h crc.c crc.h fat_common.c
|
||||
fidentify_SOURCES = fidentify.c common.c common.h phcfg.c phcfg.h setdate.c setdate.h $(file_C) $(file_H) log.c log.h crc.c crc.h fat_common.c
|
||||
|
||||
DISTCLEANFILES = *~ core
|
||||
|
||||
|
|
32
src/dir.c
32
src/dir.c
|
@ -37,9 +37,6 @@
|
|||
#include <sys/stat.h>
|
||||
#endif
|
||||
#include "types.h"
|
||||
#ifdef HAVE_UTIME_H
|
||||
#include <utime.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_IO_H
|
||||
#include <io.h>
|
||||
|
@ -331,35 +328,6 @@ int dir_whole_partition_log(disk_t *disk, const partition_t *partition, dir_data
|
|||
return dir_whole_partition_log_aux(disk, partition, dir_data, inode);
|
||||
}
|
||||
|
||||
/**
|
||||
* set_date - Set the file's date and time
|
||||
* @pathname: Path and name of the file to alter
|
||||
* @actime: Date and time to set
|
||||
* @modtime: Date and time to set
|
||||
*
|
||||
* Give a file a particular date and time.
|
||||
*
|
||||
* Return: 1 Success, set the file's date and time
|
||||
* 0 Error, failed to change the file's date and time
|
||||
*/
|
||||
int set_date(const char *pathname, time_t actime, time_t modtime)
|
||||
{
|
||||
#ifdef HAVE_UTIME
|
||||
struct utimbuf ut;
|
||||
if (!pathname)
|
||||
return 0;
|
||||
ut.actime = actime;
|
||||
ut.modtime = modtime;
|
||||
if (utime(pathname, &ut)) {
|
||||
log_error("ERROR: Couldn't set the file's date and time for %s\n", pathname);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int filesort(const struct td_list_head *a, const struct td_list_head *b)
|
||||
{
|
||||
const file_info_t *file_a=td_list_entry(a, file_info_t, list);
|
||||
|
|
|
@ -81,7 +81,6 @@ unsigned int delete_list_file(file_data_t *file_list);
|
|||
void delete_list_file_info(struct td_list_head *list);
|
||||
int dir_whole_partition_log(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int inode);
|
||||
void mode_string (const unsigned int mode, char *str);
|
||||
int set_date(const char *pathname, time_t actime, time_t modtime);
|
||||
int set_mode(const char *pathname, unsigned int mode);
|
||||
FILE *fopen_local(char **localfilename, const char *localroot, const char *filename);
|
||||
char *gen_local_filename(const char *filename);
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "log_part.h"
|
||||
#include "dirn.h"
|
||||
#include "askloc.h"
|
||||
#include "setdate.h"
|
||||
|
||||
extern const char *monstr[];
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "ext2_dir.h"
|
||||
#include "ext2_inc.h"
|
||||
#include "log.h"
|
||||
#include "setdate.h"
|
||||
|
||||
#if defined(HAVE_LIBEXT2FS)
|
||||
#define DIRENT_DELETED_FILE 4
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "dir.h"
|
||||
#include "fat_dir.h"
|
||||
#include "log.h"
|
||||
#include "setdate.h"
|
||||
|
||||
#define MSDOS_MKMODE(a,m) ((m & (a & ATTR_RO ? LINUX_S_IRUGO|LINUX_S_IXUGO : LINUX_S_IRWXUGO)) | (a & ATTR_DIR ? LINUX_S_IFDIR : LINUX_S_IFREG))
|
||||
struct fat_dir_struct
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "fat_cluster.h"
|
||||
#include "fat_unformat.h"
|
||||
#include "pnext.h"
|
||||
#include "setdate.h"
|
||||
|
||||
#define READ_SIZE 1024*512
|
||||
static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const int verbose, const int interface, unsigned int *sectors_per_cluster, uint64_t *offset_org, alloc_data_t *list_search_space)
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
#include "ntfs_utl.h"
|
||||
#include "ntfs_inc.h"
|
||||
#include "log.h"
|
||||
#include "setdate.h"
|
||||
|
||||
#ifdef HAVE_LIBNTFS
|
||||
#define MAX_PATH 1024
|
||||
|
|
|
@ -93,6 +93,7 @@
|
|||
#include "ntfs_dir.h"
|
||||
#include "ntfs_utl.h"
|
||||
#include "askloc.h"
|
||||
#include "setdate.h"
|
||||
|
||||
extern const char *monstr[];
|
||||
|
||||
|
|
60
src/setdate.c
Normal file
60
src/setdate.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
|
||||
File: setdate.c
|
||||
|
||||
Copyright (C) 1998-2009 Christophe GRENIER <grenier@cgsecurity.org>
|
||||
|
||||
This software 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 the Free Software Foundation, Inc., 51
|
||||
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "types.h"
|
||||
#ifdef HAVE_UTIME_H
|
||||
#include <utime.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include "log.h"
|
||||
#include "setdate.h"
|
||||
|
||||
/**
|
||||
* set_date - Set the file's date and time
|
||||
* @pathname: Path and name of the file to alter
|
||||
* @actime: Date and time to set
|
||||
* @modtime: Date and time to set
|
||||
*
|
||||
* Give a file a particular date and time.
|
||||
*
|
||||
* Return: 1 Success, set the file's date and time
|
||||
* 0 Error, failed to change the file's date and time
|
||||
*/
|
||||
int set_date(const char *pathname, time_t actime, time_t modtime)
|
||||
{
|
||||
#ifdef HAVE_UTIME
|
||||
struct utimbuf ut;
|
||||
if (!pathname)
|
||||
return 0;
|
||||
ut.actime = actime;
|
||||
ut.modtime = modtime;
|
||||
if (utime(pathname, &ut)) {
|
||||
log_error("ERROR: Couldn't set the file's date and time for %s\n", pathname);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
31
src/setdate.h
Normal file
31
src/setdate.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
|
||||
File: setdate.h
|
||||
|
||||
Copyright (C) 2009 Christophe GRENIER <grenier@cgsecurity.org>
|
||||
|
||||
This software 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 the Free Software Foundation, Inc., 51
|
||||
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
*/
|
||||
#ifndef _SETDATE_H
|
||||
#define _SETDATE_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int set_date(const char *pathname, time_t actime, time_t modtime);
|
||||
#ifdef __cplusplus
|
||||
} /* closing brace for extern "C" */
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in a new issue