fsmagic.c (267897) | fsmagic.c (275698) |
---|---|
1/* 2 * Copyright (c) Ian F. Darwin 1986-1995. 3 * Software written by Ian F. Darwin and others; 4 * maintained 1995-present by Christos Zoulas and others. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 18 unchanged lines hidden (view full) --- 27 */ 28/* 29 * fsmagic - magic based on filesystem info - directory, special files, etc. 30 */ 31 32#include "file.h" 33 34#ifndef lint | 1/* 2 * Copyright (c) Ian F. Darwin 1986-1995. 3 * Software written by Ian F. Darwin and others; 4 * maintained 1995-present by Christos Zoulas and others. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 18 unchanged lines hidden (view full) --- 27 */ 28/* 29 * fsmagic - magic based on filesystem info - directory, special files, etc. 30 */ 31 32#include "file.h" 33 34#ifndef lint |
35FILE_RCSID("@(#)$File: fsmagic.c,v 1.73 2014/05/14 23:15:42 christos Exp $") | 35FILE_RCSID("@(#)$File: fsmagic.c,v 1.75 2014/12/04 15:56:46 christos Exp $") |
36#endif /* lint */ 37 38#include "magic.h" 39#include <string.h> 40#ifdef HAVE_UNISTD_H 41#include <unistd.h> 42#endif 43#include <stdlib.h> --- 26 unchanged lines hidden (view full) --- 70 int mime = ms->flags & MAGIC_MIME; 71 if ((mime & MAGIC_MIME_TYPE) && 72 file_printf(ms, "inode/symlink") 73 == -1) 74 return -1; 75 else if (!mime) { 76 if (ms->flags & MAGIC_ERROR) { 77 file_error(ms, err, | 36#endif /* lint */ 37 38#include "magic.h" 39#include <string.h> 40#ifdef HAVE_UNISTD_H 41#include <unistd.h> 42#endif 43#include <stdlib.h> --- 26 unchanged lines hidden (view full) --- 70 int mime = ms->flags & MAGIC_MIME; 71 if ((mime & MAGIC_MIME_TYPE) && 72 file_printf(ms, "inode/symlink") 73 == -1) 74 return -1; 75 else if (!mime) { 76 if (ms->flags & MAGIC_ERROR) { 77 file_error(ms, err, |
78 "broken symbolic link to `%s'", buf); | 78 "broken symbolic link to %s", buf); |
79 return -1; 80 } | 79 return -1; 80 } |
81 if (file_printf(ms, "broken symbolic link to `%s'", buf) == -1) | 81 if (file_printf(ms, "broken symbolic link to %s", buf) == -1) |
82 return -1; 83 } 84 return 1; 85} 86#endif 87private int 88handle_mime(struct magic_set *ms, int mime, const char *str) 89{ --- 34 unchanged lines hidden (view full) --- 124 if ((ms->flags & MAGIC_SYMLINK) == 0) 125 ret = lstat(fn, sb); 126 else 127#endif 128 ret = stat(fn, sb); /* don't merge into if; see "ret =" above */ 129 130#ifdef WIN32 131 { | 82 return -1; 83 } 84 return 1; 85} 86#endif 87private int 88handle_mime(struct magic_set *ms, int mime, const char *str) 89{ --- 34 unchanged lines hidden (view full) --- 124 if ((ms->flags & MAGIC_SYMLINK) == 0) 125 ret = lstat(fn, sb); 126 else 127#endif 128 ret = stat(fn, sb); /* don't merge into if; see "ret =" above */ 129 130#ifdef WIN32 131 { |
132 HANDLE hFile = CreateFile(fn, 0, FILE_SHARE_DELETE | | 132 HANDLE hFile = CreateFile((LPCSTR)fn, 0, FILE_SHARE_DELETE | |
133 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 134 NULL); 135 if (hFile != INVALID_HANDLE_VALUE) { 136 /* 137 * Stat failed, but we can still open it - assume it's 138 * a block device, if nothing else. 139 */ 140 if (ret) { --- 206 unchanged lines hidden (view full) --- 347 p = magic_file(ms, buf); 348 ms->flags |= MAGIC_SYMLINK; 349 if (p == NULL) 350 return -1; 351 } else { /* just print what it points to */ 352 if (mime) { 353 if (handle_mime(ms, mime, "symlink") == -1) 354 return -1; | 133 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 134 NULL); 135 if (hFile != INVALID_HANDLE_VALUE) { 136 /* 137 * Stat failed, but we can still open it - assume it's 138 * a block device, if nothing else. 139 */ 140 if (ret) { --- 206 unchanged lines hidden (view full) --- 347 p = magic_file(ms, buf); 348 ms->flags |= MAGIC_SYMLINK; 349 if (p == NULL) 350 return -1; 351 } else { /* just print what it points to */ 352 if (mime) { 353 if (handle_mime(ms, mime, "symlink") == -1) 354 return -1; |
355 } else if (file_printf(ms, "%ssymbolic link to `%s'", | 355 } else if (file_printf(ms, "%ssymbolic link to %s", |
356 COMMA, buf) == -1) 357 return -1; 358 } 359 break; 360#endif 361#ifdef S_IFSOCK 362#ifndef __COHERENT__ 363 case S_IFSOCK: --- 44 unchanged lines hidden --- | 356 COMMA, buf) == -1) 357 return -1; 358 } 359 break; 360#endif 361#ifdef S_IFSOCK 362#ifndef __COHERENT__ 363 case S_IFSOCK: --- 44 unchanged lines hidden --- |