Removed directory and symlink special cases from

GuessMimeType(entry_ref*) and placed them in
Database::GuessMimeType(entry_ref*)


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1329 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-10-01 07:34:15 +00:00
parent 86c6e9c1c1
commit a551958795
+5 -25
View File
@@ -129,9 +129,8 @@ SnifferRules::~SnifferRules()
/*! \brief Guesses a MIME type for the supplied entry_ref. /*! \brief Guesses a MIME type for the supplied entry_ref.
Only the data in the given entry is considered, not the filename or Only the data in the given entry is considered, not the filename or
its extension. its extension. Please see GuessMimeType(BPositionIO*, BString*) for
more details.
Please see GuessMimeType(BPositionIO*, BString*) for more details.
\param ref The entry to sniff \param ref The entry to sniff
\param type Pointer to a pre-allocated BString which is set to the \param type Pointer to a pre-allocated BString which is set to the
@@ -145,26 +144,10 @@ status_t
SnifferRules::GuessMimeType(const entry_ref *ref, BString *type) SnifferRules::GuessMimeType(const entry_ref *ref, BString *type)
{ {
status_t err = ref && type ? B_OK : B_BAD_VALUE; status_t err = ref && type ? B_OK : B_BAD_VALUE;
ssize_t bytes = 0; ssize_t bytes = 0;
char *buffer = NULL; char *buffer = NULL;
// See if we have a directory, a symlink, or a vanilla file
BNode node;
struct stat statData;
if (!err)
err = node.SetTo(ref);
if (!err)
err = node.GetStat(&statData);
if (!err) {
if (S_ISDIR(statData.st_mode)) {
// Directory
type->SetTo(kDirectoryType);
} else if (S_ISLNK(statData.st_mode)) {
// Symlink
type->SetTo(kSymlinkType);
} else if (S_ISREG(statData.st_mode)) {
// Regular file
BFile file; BFile file;
// First find out the max number of bytes we need to read // First find out the max number of bytes we need to read
// from the file to fully accomodate all of our currently // from the file to fully accomodate all of our currently
// installed sniffer rules // installed sniffer rules
@@ -173,6 +156,7 @@ SnifferRules::GuessMimeType(const entry_ref *ref, BString *type)
if (bytes < 0) if (bytes < 0)
err = bytes; err = bytes;
} }
// Next read that many bytes (or fewer, if the file isn't // Next read that many bytes (or fewer, if the file isn't
// that long) into a buffer // that long) into a buffer
if (!err) { if (!err) {
@@ -187,16 +171,12 @@ SnifferRules::GuessMimeType(const entry_ref *ref, BString *type)
if (bytes < 0) if (bytes < 0)
err = bytes; err = bytes;
} }
// Now sniff the buffer // Now sniff the buffer
if (!err) { if (!err) {
BMemoryIO data(buffer, bytes); BMemoryIO data(buffer, bytes);
err = GuessMimeType(&data, type); err = GuessMimeType(&data, type);
} }
} else {
// ?????
err = B_FILE_ERROR;
}
}
return err; return err;
} }