2 * Copyright (C) 2005 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #define LOG_TAG "misc"
20 // Miscellaneous utility functions.
22 #include <androidfw/misc.h>
29 using namespace android;
36 FileType getFileType(const char* fileName)
40 if (stat(fileName, &sb) < 0) {
41 if (errno == ENOENT || errno == ENOTDIR)
42 return kFileTypeNonexistent;
44 fprintf(stderr, "getFileType got errno=%d on '%s'\n",
46 return kFileTypeUnknown;
49 if (S_ISREG(sb.st_mode))
50 return kFileTypeRegular;
51 else if (S_ISDIR(sb.st_mode))
52 return kFileTypeDirectory;
53 else if (S_ISCHR(sb.st_mode))
54 return kFileTypeCharDev;
55 else if (S_ISBLK(sb.st_mode))
56 return kFileTypeBlockDev;
57 else if (S_ISFIFO(sb.st_mode))
60 else if (S_ISLNK(sb.st_mode))
61 return kFileTypeSymlink;
64 else if (S_ISSOCK(sb.st_mode))
65 return kFileTypeSocket;
68 return kFileTypeUnknown;
73 * Get a file's modification date.
75 time_t getFileModDate(const char* fileName)
79 if (stat(fileName, &sb) < 0)
85 }; // namespace android