archive_entry_copy_stat.c revision 228763
1139827Simp/*- 2194619Srwatson * Copyright (c) 2003-2007 Tim Kientzle 3133422Srwatson * All rights reserved. 4133422Srwatson * 5133422Srwatson * Redistribution and use in source and binary forms, with or without 6133422Srwatson * modification, are permitted provided that the following conditions 7133422Srwatson * are met: 8133422Srwatson * 1. Redistributions of source code must retain the above copyright 9133422Srwatson * notice, this list of conditions and the following disclaimer. 10133422Srwatson * 2. Redistributions in binary form must reproduce the above copyright 11133422Srwatson * notice, this list of conditions and the following disclaimer in the 12133422Srwatson * documentation and/or other materials provided with the distribution. 13133422Srwatson * 14133422Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15133422Srwatson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16133422Srwatson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17133422Srwatson * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18133422Srwatson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19133422Srwatson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20133422Srwatson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21133422Srwatson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22133422Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23133422Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24133422Srwatson */ 25165891Srwatson 26165974Srwatson#include "archive_platform.h" 2756555Sbrian__FBSDID("$FreeBSD: head/contrib/libarchive/libarchive/archive_entry_copy_stat.c 228763 2011-12-21 11:13:29Z mm $"); 28133422Srwatson 29133422Srwatson#ifdef HAVE_SYS_STAT_H 30133422Srwatson#include <sys/stat.h> 31133422Srwatson#endif 32133422Srwatson 33133422Srwatson#include "archive_entry.h" 34133422Srwatson 35133422Srwatsonvoid 36133422Srwatsonarchive_entry_copy_stat(struct archive_entry *entry, const struct stat *st) 37133422Srwatson{ 38133422Srwatson#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 39133422Srwatson archive_entry_set_atime(entry, st->st_atime, st->st_atimespec.tv_nsec); 40133422Srwatson archive_entry_set_ctime(entry, st->st_ctime, st->st_ctimespec.tv_nsec); 41133422Srwatson archive_entry_set_mtime(entry, st->st_mtime, st->st_mtimespec.tv_nsec); 42133422Srwatson#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 43133422Srwatson archive_entry_set_atime(entry, st->st_atime, st->st_atim.tv_nsec); 44133422Srwatson archive_entry_set_ctime(entry, st->st_ctime, st->st_ctim.tv_nsec); 45133422Srwatson archive_entry_set_mtime(entry, st->st_mtime, st->st_mtim.tv_nsec); 46133422Srwatson#elif HAVE_STRUCT_STAT_ST_MTIME_N 47133422Srwatson archive_entry_set_atime(entry, st->st_atime, st->st_atime_n); 48133422Srwatson archive_entry_set_ctime(entry, st->st_ctime, st->st_ctime_n); 4956555Sbrian archive_entry_set_mtime(entry, st->st_mtime, st->st_mtime_n); 5015885Sjulian#elif HAVE_STRUCT_STAT_ST_UMTIME 5115885Sjulian archive_entry_set_atime(entry, st->st_atime, st->st_uatime * 1000); 5215885Sjulian archive_entry_set_ctime(entry, st->st_ctime, st->st_uctime * 1000); 5315885Sjulian archive_entry_set_mtime(entry, st->st_mtime, st->st_umtime * 1000); 5495759Stanimura#elif HAVE_STRUCT_STAT_ST_MTIME_USEC 5515885Sjulian archive_entry_set_atime(entry, st->st_atime, st->st_atime_usec * 1000); 5695759Stanimura archive_entry_set_ctime(entry, st->st_ctime, st->st_ctime_usec * 1000); 5715885Sjulian archive_entry_set_mtime(entry, st->st_mtime, st->st_mtime_usec * 1000); 5815885Sjulian#else 5995759Stanimura archive_entry_set_atime(entry, st->st_atime, 0); 6095759Stanimura archive_entry_set_ctime(entry, st->st_ctime, 0); 6115885Sjulian archive_entry_set_mtime(entry, st->st_mtime, 0); 6215885Sjulian#if HAVE_STRUCT_STAT_ST_BIRTHTIME 6315885Sjulian archive_entry_set_birthtime(entry, st->st_birthtime, 0); 6418207Sbde#endif 6518207Sbde#endif 6618207Sbde#if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 6718207Sbde archive_entry_set_birthtime(entry, st->st_birthtime, st->st_birthtimespec.tv_nsec); 68132043Srwatson#endif 6915885Sjulian archive_entry_set_dev(entry, st->st_dev); 7015885Sjulian archive_entry_set_gid(entry, st->st_gid); 71163606Srwatson archive_entry_set_uid(entry, st->st_uid); 72163606Srwatson archive_entry_set_ino(entry, st->st_ino); 7329185Sbde archive_entry_set_nlink(entry, st->st_nlink); 7429185Sbde archive_entry_set_rdev(entry, st->st_rdev); 7529184Sbde archive_entry_set_size(entry, st->st_size); 76132043Srwatson archive_entry_set_mode(entry, st->st_mode); 7729185Sbde} 7829184Sbde