int file_is_type(char *path, char *base_path, int flag) { struct stat *s; char *fullpath; int ret; SAFE_CALLOC(s, 1, sizeof(struct stat)); if (base_path) { ret = file_absolute_path(base_path, path, &fullpath); if (ret != ESUCCESS) return -EFAILURE; } else fullpath = path; ret = stat(fullpath, s); if (ret < 0) { // DEBUG_MSG(D_ERROR, "%s error performing stat on %s [%s]", __func__, fullpath, strerror(errno)); return -EINVALID; } if (fullpath != path) SAFE_FREE(fullpath); if (s->st_mode & flag) { SAFE_FREE(s); return ESUCCESS; } SAFE_FREE(s); return -EFAILURE; }
off_t file_get_size(char *path, char *base_path) { struct stat *s; char *fullpath; int ret; off_t size; SAFE_CALLOC(s, 1, sizeof(struct stat)); if (base_path) { ret = file_absolute_path(base_path, path, &fullpath); if (ret != ESUCCESS) return -EFAILURE; } else fullpath = path; ret = stat(fullpath, s); if (ret < 0) { DEBUG_MSG(D_ERROR, "error performing stat on %s", fullpath); return -EINVALID; } if (fullpath != path) SAFE_FREE(fullpath); size = s->st_size; SAFE_FREE(s); return size; }
int main(int argc, char **argv) { printf("===========================absolute-path=============\n"); file_absolute_path(); printf("\n"); printf("===========================path-phase=============\n"); file_path_phase("/home/grocery-shop/language/" "python/requestsPackage/sendRequest.py"); printf("\n"); return 0; }