Path: blob/master/Utilities/cmlibarchive/libarchive/archive_entry_strmode.c
3153 views
/*-1* Copyright (c) 2003-2007 Tim Kientzle2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR14* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES15* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,17* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT18* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,19* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY20* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT21* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF22* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23*/2425#include "archive_platform.h"2627#ifdef HAVE_SYS_STAT_H28#include <sys/stat.h>29#endif30#ifdef HAVE_STRING_H31#include <string.h>32#endif3334#include "archive_entry.h"35#include "archive_entry_private.h"3637const char *38archive_entry_strmode(struct archive_entry *entry)39{40static const mode_t permbits[] =41{ 0400, 0200, 0100, 0040, 0020, 0010, 0004, 0002, 0001 };42char *bp = entry->strmode;43mode_t mode;44int i;4546/* Fill in a default string, then selectively override. */47strcpy(bp, "?rwxrwxrwx ");4849mode = archive_entry_mode(entry);50switch (archive_entry_filetype(entry)) {51case AE_IFREG: bp[0] = '-'; break;52case AE_IFBLK: bp[0] = 'b'; break;53case AE_IFCHR: bp[0] = 'c'; break;54case AE_IFDIR: bp[0] = 'd'; break;55case AE_IFLNK: bp[0] = 'l'; break;56case AE_IFSOCK: bp[0] = 's'; break;57case AE_IFIFO: bp[0] = 'p'; break;58default:59if (archive_entry_hardlink(entry) != NULL) {60bp[0] = 'h';61break;62}63}6465for (i = 0; i < 9; i++)66if (!(mode & permbits[i]))67bp[i+1] = '-';6869if (mode & S_ISUID) {70if (mode & 0100) bp[3] = 's';71else bp[3] = 'S';72}73if (mode & S_ISGID) {74if (mode & 0010) bp[6] = 's';75else bp[6] = 'S';76}77if (mode & S_ISVTX) {78if (mode & 0001) bp[9] = 't';79else bp[9] = 'T';80}81if (archive_entry_acl_types(entry) != 0)82bp[10] = '+';8384return (bp);85}868788