180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2011 Google Inc.
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkOSFile.h"
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek SollenbergerSkString SkOSPath::SkPathJoin(const char *rootPath, const char *relativePath) {
1058190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    SkString result(rootPath);
1158190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    if (!result.endsWith(SkPATH_SEPARATOR)) {
1258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger        result.appendUnichar(SkPATH_SEPARATOR);
1358190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    }
1458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    result.append(relativePath);
1558190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    return result;
1658190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger}
1758190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger
1858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek SollenbergerSkString SkOSPath::SkBasename(const char* fullPath) {
1958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    if (!fullPath) {
2058190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger        return SkString();
2158190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    }
2258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    const char* filename = strrchr(fullPath, SkPATH_SEPARATOR);
2358190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    if (NULL == filename) {
2458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger        filename = fullPath;
2558190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    } else {
2658190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger        ++filename;
2758190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    }
2858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    return SkString(filename);
2958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger}
3058190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_BUILD_FOR_WIN
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic uint16_t* concat_to_16(const char src[], const char suffix[])
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    size_t  i, len = strlen(src);
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    size_t  len2 = 3 + (suffix ? strlen(suffix) : 0);
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint16_t* dst = (uint16_t*)sk_malloc_throw((len + len2) * sizeof(uint16_t));
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    for (i = 0; i < len; i++)
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        dst[i] = src[i];
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (i > 0 && dst[i-1] != '/')
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        dst[i++] = '/';
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    dst[i++] = '*';
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (suffix)
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        while (*suffix)
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            dst[i++] = *suffix++;
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    dst[i] = 0;
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkASSERT(i + 1 <= len + len2);
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return dst;
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkUTF16_Str::SkUTF16_Str(const char src[])
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    size_t  len = strlen(src);
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    fStr = (uint16_t*)sk_malloc_throw((len + 1) * sizeof(uint16_t));
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    size_t i;
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    for (i = 0; i < len; i++)
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fStr[i] = src[i];
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    fStr[i] = 0;
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////////////
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkOSFile::Iter::Iter() : fHandle(0), fPath16(NULL)
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkOSFile::Iter::Iter(const char path[], const char suffix[]) : fHandle(0), fPath16(NULL)
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    this->reset(path, suffix);
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkOSFile::Iter::~Iter()
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    sk_free(fPath16);
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (fHandle)
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        ::FindClose(fHandle);
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkOSFile::Iter::reset(const char path[], const char suffix[])
8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (fHandle)
8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        ::FindClose(fHandle);
9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fHandle = 0;
9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (NULL == path)
9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        path = "";
9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    sk_free(fPath16);
9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    fPath16 = concat_to_16(path, suffix);
9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic bool is_magic_dir(const uint16_t dir[])
10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // return true for "." and ".."
10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return dir[0] == '.' && (dir[1] == 0 || dir[1] == '.' && dir[2] == 0);
10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic bool get_the_file(HANDLE handle, SkString* name, WIN32_FIND_DATAW* dataPtr, bool getDir)
10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    WIN32_FIND_DATAW    data;
10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (NULL == dataPtr)
11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (::FindNextFileW(handle, &data))
11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            dataPtr = &data;
11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        else
11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return false;
11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    for (;;)
11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (getDir)
12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        {
12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if ((dataPtr->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !is_magic_dir((uint16_t*)dataPtr->cFileName))
12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                break;
12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        else
12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        {
12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (!(dataPtr->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                break;
12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (!::FindNextFileW(handle, dataPtr))
13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return false;
13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // if we get here, we've found a file/dir
13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (name)
13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        name->setUTF16((uint16_t*)dataPtr->cFileName);
13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return true;
13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkOSFile::Iter::next(SkString* name, bool getDir)
14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    WIN32_FIND_DATAW    data;
14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    WIN32_FIND_DATAW*   dataPtr = NULL;
14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (fHandle == 0)   // our first time
14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (fPath16 == NULL || *fPath16 == 0)    // check for no path
14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return false;
14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fHandle = ::FindFirstFileW((LPCWSTR)fPath16, &data);
15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (fHandle != 0 && fHandle != (HANDLE)~0)
15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            dataPtr = &data;
15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return fHandle != (HANDLE)~0 && get_the_file(fHandle, name, dataPtr, getDir);
15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_IOS)
15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if 0
15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruOSStatus FSPathMakeRef (
16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru   const UInt8 * path,
16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru   FSRef * ref,
16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru   Boolean * isDirectory
16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru);
16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkOSFile::Iter::Iter() : fDIR(0)
16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkOSFile::Iter::Iter(const char path[], const char suffix[]) : fDIR(0)
17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    this->reset(path, suffix);
17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
17480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkOSFile::Iter::~Iter()
17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (fDIR)
17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        ::closedir(fDIR);
17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkOSFile::Iter::reset(const char path[], const char suffix[])
18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (fDIR)
18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        ::closedir(fDIR);
18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fDIR = 0;
18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    fPath.set(path);
19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (path)
19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fDIR = ::opendir(path);
19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fSuffix.set(suffix);
19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    else
19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fSuffix.reset();
19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// returns true if suffix is empty, or if str ends with suffix
20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic bool issuffixfor(const SkString& suffix, const char str[])
20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    size_t  suffixLen = suffix.size();
20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    size_t  strLen = strlen(str);
20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return  strLen >= suffixLen &&
20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            memcmp(suffix.c_str(), str + strLen - suffixLen, suffixLen) == 0;
20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include <sys/stat.h>
21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkOSFile::Iter::next(SkString* name, bool getDir)
21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{
21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (fDIR)
21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    {
21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        dirent* entry;
21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        while ((entry = ::readdir(fDIR)) != NULL)
21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        {
21980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            struct stat s;
22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            SkString    str(fPath);
22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (!str.endsWith("/") && !str.endsWith("\\"))
22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                str.append("/");
22480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            str.append(entry->d_name);
22580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (0 == stat(str.c_str(), &s))
22780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            {
22880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                if (getDir)
22980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                {
23080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    if (s.st_mode & S_IFDIR)
23180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                        break;
23280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                }
23380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                else
23480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                {
23580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    if (!(s.st_mode & S_IFDIR) && issuffixfor(fSuffix, entry->d_name))
23680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                        break;
23780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                }
23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
23980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (entry)  // we broke out with a file
24180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        {
24280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (name)
24380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                name->set(entry->d_name);
24480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return true;
24580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
24680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
24780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return false;
24880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
24958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger#endif // if one of:SK_BUILD_FOR_MAC, SK_BUILD_FOR_UNIX, SK_BUILD_FOR_ANDROID,SK_BUILD_FOR_IOS
250