コード例 #1
0
ファイル: pcsl_armsd.c プロジェクト: jiangxilong/yari
/**
 * The rename function updates the filename.
 */
int pcsl_file_rename(const pcsl_string * oldName, 
		     const pcsl_string * newName)
{
    int status;
    const jbyte * pszOldFilename = pcsl_string_get_utf8_data(oldName);

    if (pszOldFilename == NULL) {
      return -1;
    }

    {
      const jbyte * pszNewFilename = pcsl_string_get_utf8_data(newName);

      if (pszNewFilename == NULL) {
	pcsl_string_release_utf8_data(pszOldFilename, oldName);
	return -1;
      }

      if (rename((char*)pszOldFilename, (char*)pszNewFilename) < 0) {
        status = -1;
      } else {
        status = 0;
      }

      pcsl_string_release_utf8_data(pszOldFilename, oldName);
      pcsl_string_release_utf8_data(pszNewFilename, newName);

      return status;
    }
}
コード例 #2
0
ファイル: pcsl_posix.c プロジェクト: sfsy1989/j2me
/**
 * The open function creates and returns a new file identifier for the 
 * file named by filename. Initially, the file position indicator for the 
 * file is at the beginning of the file.
 * 
 */
int pcsl_file_open(const pcsl_string * fileName, int flags, void **handle)
{
    int   fd;
    int   creationMode = 0;
    const jbyte * pszOsFilename = pcsl_string_get_utf8_data(fileName);

    if (pszOsFilename == NULL) {
      return -1;
    }

    if((flags & PCSL_FILE_O_CREAT) == PCSL_FILE_O_CREAT) {
        creationMode = DEFAULT_FILE_CREATION_MODE;
    }

#if PCSL_PLATFORM_ARM
    fd = open((char*)pszOsFilename, flags, creationMode);
#endif
 
#if PCSL_PLATFORM_MIPS
    #define FLAGS_MIPS ((flags > 0)?(O_RDWR | O_CREAT):flags)
    fd = open((char*)pszOsFilename, FLAGS_MIPS, creationMode);
#endif

    pcsl_string_release_utf8_data(pszOsFilename, fileName);

    if (fd < 0) {
        *handle = NULL;
        return -1;
    }

    *handle = (void *)fd;
    return 0;
}
コード例 #3
0
ファイル: pcsl_dir_posix.c プロジェクト: jiangxilong/yari
/**
 * The function returns value of the time for the specified file.
 */
int pcsl_file_get_time(const pcsl_string * fileName, int type, long* result)
{
    struct stat sbuf;
    int   status = -1;
    const jbyte * pszName = pcsl_string_get_utf8_data(fileName);

    if (pszName == NULL) {
      return -1;
    }
    
    *result = 0;
    
    status = stat((char*)pszName, &sbuf);

    pcsl_string_release_utf8_data(pszName, fileName);
        
    if (status == 0)
    {
        switch (type) {
        case PCSL_FILE_TIME_LAST_MODIFIED:
            *result = sbuf.st_mtime;
            break;        
        default:
            return -1;
        }        
        return 0;
    }
    
    return -1;
}
コード例 #4
0
ファイル: midpJar.c プロジェクト: jiangxilong/yari
int
midpJarEntryExists(void* handle, const pcsl_string * name) {
    MidpJarInfo* pJarInfo = (MidpJarInfo*)handle;
    JarEntryInfo entryInfo;
    unsigned char* pName;
    int nameLen;
    unsigned char* pCompBuffer;

    /* Jar entry names are UTF-8 */
    pName = (unsigned char *)pcsl_string_get_utf8_data(name);
    if (NULL == pName) {
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }

    nameLen = pcsl_string_utf8_length(name);
    pCompBuffer = midpMalloc(nameLen);
    if (NULL == pCompBuffer) {
        pcsl_string_release_utf8_data((jbyte*)pName, name);
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }
    
    entryInfo = findJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo,
                pName, nameLen, pCompBuffer);
    pcsl_string_release_utf8_data((jbyte*)pName, name);
    midpFree(pCompBuffer);
    if (JAR_ENTRY_NOT_FOUND == entryInfo.status) {
        return 0;
    }

    if (entryInfo.status != 0) {
        return MIDP_JAR_CORRUPT_ERROR;
    }

    return 1;
}
コード例 #5
0
ファイル: pcsl_armsd.c プロジェクト: jiangxilong/yari
/**
 * Check if the file exists in FS storage.
 */
int pcsl_file_exist(const pcsl_string * fileName)
{
    FILE* fd;
    int status = 0;
    const jbyte * pszOsFilename = pcsl_string_get_utf8_data(fileName);

    if (pszOsFilename == NULL) {
      return 0;
    }

    {
      const jsize len = strlen(pszOsFilename);
      // in special case of directories we always return false
      if (pszOsFilename && len > 0 && 
	  pszOsFilename[len - 1] == '/') {
	return 0;
      }
    }

    if ((fd = fopen((char*)pszOsFilename,"r")) !=0 ) {
       fclose(fd);
       status = 1;
    }     

    pcsl_string_release_utf8_data(pszOsFilename, fileName);

    return status;

}
コード例 #6
0
ファイル: pcsl_rmfs.c プロジェクト: Sektor/phoneme-qtopia
/**
 * The open function creates and returns a new file identifier for the 
 * file named by filename. Initially, the file position indicator for the 
 * file is at the beginning of the file.
 * 
 */
int pcsl_file_open(const pcsl_string * fileName, int flags, void **handle) {

    int fd;
    int mode = 0;
    const jbyte * pszOsFilename = pcsl_string_get_utf8_data(fileName);

    if (pszOsFilename == NULL) {
	return -1;
    }

    if ((flags & PCSL_FILE_O_CREAT) == PCSL_FILE_O_CREAT) {
        mode = 0664;
    }

    fd = rmfsOpen(pszOsFilename, flags, mode);

    pcsl_string_release_utf8_data(pszOsFilename, fileName);

    if (fd < 0) {
	*handle = NULL;
        return -1;
    }

    *handle = (void *)fd;
    return 0;
	
}
コード例 #7
0
ファイル: midpDebug.c プロジェクト: Sektor/phoneme-qtopia
void
printPcslStringWithMessageImpl(char* message, const pcsl_string* pstr) {
    char* tag;

    if ((pcsl_string_length(pstr) <= 0) && (!message)) {
        REPORT_INFO(LC_MIDPSTRING,
		    "printPcslStringWithMessage() No input");
        return;
    }

    if (message) {
        tag = message;
    } else {
        tag = "message = NULL:";
    }

    if (pcsl_string_length(pstr) > 0) {
        const char* msg = pcsl_string_get_utf8_data(pstr);
        if (msg) {
            REPORT_INFO2(LC_MIDPSTRING, "%s: %s", tag, msg);
            pcsl_string_release_utf8_data(msg, pstr);
        } else {
           REPORT_INFO1(LC_MIDPSTRING,
	        "%s: printPcslStringWithMessage can't convert pcsl_string to char*", tag);
        }
    } else {
        REPORT_INFO2(LC_MIDPSTRING, "%s: pcsl_string is %s", tag,
            0 == pcsl_string_length(pstr) ? "empty" : "null" );
    }
}
コード例 #8
0
ファイル: pcsl_armsd.c プロジェクト: jiangxilong/yari
/**
 * The open function creates and returns a new file identifier for the 
 * file named by filename. Initially, the file position indicator for the 
 * file is at the beginning of the file. The argument  creationMode  is used 
 * only when a file is created
 */
int pcsl_file_open(const pcsl_string * fileName, int flags, void **handle) {
    
    int fd;
    char* mode;
    const jbyte * pszOsFilename = pcsl_string_get_utf8_data(fileName);

    if (pszOsFilename == NULL) {
      return -1;
    }

    if (flags == O_RDONLY) {
        mode = "rb";
    } else if (flags == O_WRONLY) {
        mode = "wb";
    } else if (flags == RDWR_CREATE || flags == RDWR_CREATE_TRUNC || flags == RDWR_TRUNC) {
        mode = "w+b";
    } else {
        mode = "r+b";
    }

    fd = (int)fopen((char*)pszOsFilename, mode);

    pcsl_string_release_utf8_data(pszOsFilename, fileName);

    if (fd == 0) {
        *handle = NULL;
        return -1;
    } else {
        *handle  = (void *)fd;
        return 0;
    }
}
コード例 #9
0
ファイル: pcsl_rmfs.c プロジェクト: Sektor/phoneme-qtopia
/*
 * The opendir function opens directory named dirname. 
 */
void* pcsl_file_opendir(const pcsl_string * dirName)
{
    DIR* dir;
    const jbyte * pszOsFilename = pcsl_string_get_utf8_data(dirName);

    dir = rmfsOpendir(pszOsFilename);

    pcsl_string_release_utf8_data(pszOsFilename, dirName);

    return dir;
}
コード例 #10
0
ファイル: midpJar.c プロジェクト: jiangxilong/yari
/* Returns the entry size or less than zero if error.
 *  If the entry does not exist, size is 0 and *ppEntry is NULL
 */
long
midpGetJarEntry(void* handle, const pcsl_string * name,
                unsigned char** ppEntry) {
    MidpJarInfo* pJarInfo = (MidpJarInfo*)handle;
    JarEntryInfo entryInfo;
    char*  entryData = NULL;
    int status;
    unsigned char* pName;
    int nameLen;
    unsigned char* pCompBuffer;

    *ppEntry = NULL;

    /* Jar entry names are UTF-8 */
    pName = (unsigned char *)pcsl_string_get_utf8_data(name);
    if (pName == NULL) {
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }

    nameLen = pcsl_string_utf8_length(name);
    pCompBuffer = midpMalloc(nameLen);
    if (pCompBuffer == NULL) {
        pcsl_string_release_utf8_data((jbyte*)pName, name);
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }
    
    entryInfo = findJarEntryInfo(&pJarInfo->fileObj, &pJarInfo->jarInfo,
                pName, nameLen, pCompBuffer);
    pcsl_string_release_utf8_data((jbyte*)pName, name);
    midpFree(pCompBuffer);
    if (entryInfo.status == JAR_ENTRY_NOT_FOUND) {
        return 0;
    }
    
    if (entryInfo.status != 0) {
        return MIDP_JAR_CORRUPT_ERROR;
    }

    entryData = midpMalloc((size_t)entryInfo.decompLen);
    if (entryData == NULL) {
        return MIDP_JAR_OUT_OF_MEM_ERROR;
    }

    status = inflateJarEntry(&pJarInfo->fileObj, &pJarInfo->heapManObj,
                             &entryInfo, (unsigned char*)entryData, 0);
    if (status != 0) {
        midpFree(entryData);
        return MIDP_JAR_CORRUPT_ERROR;
    }

    *ppEntry = (unsigned char*)entryData;
    return entryInfo.decompLen;
}
コード例 #11
0
/*
* IMPL_NOTE: this function is the same as midpGetJarEntry() in midpJar.c,
* but it uses only CLDC stuff
*/
jboolean
midp_readJarEntry(const pcsl_string* jarName, const pcsl_string* entryName, jobject* entry) {
    JvmPathChar* platformJarName;
    int i;
    jboolean noerror = KNI_TRUE;

    GET_PCSL_STRING_DATA_AND_LENGTH(jarName)
    /* Entry names in JARs are UTF-8. */
    const jbyte * const platformEntryName = pcsl_string_get_utf8_data(entryName);

    do {
        if (platformEntryName == NULL) {
            noerror = KNI_FALSE;
            break;
        }
        /*
         * JvmPathChars can be either 16 bits or 8 bits so we can't
         * assume either.
         */

        /*
         * Conversion to JvmPathChars is only temporary, we should change the VM
         * should take a jchar array and a length and pass that to
         * PCSL which will then perform
         * a platform specific conversion (DBCS on Win32 or UTF8 on Linux)
         */
        platformJarName = midpMalloc((jarName_len + 1) * sizeof (JvmPathChar));
        if (platformJarName == NULL) {
            noerror = KNI_FALSE;
            break;
        }

        for (i = 0; i < jarName_len; i++) {
            platformJarName[i] = (JvmPathChar)jarName_data[i];
        }

        platformJarName[i] = 0;

        Jvm_read_jar_entry(platformJarName, (char*)platformEntryName, (jobject)*entry);
        midpFree(platformJarName);
    } while(0);
    pcsl_string_release_utf8_data(platformEntryName, entryName);
    RELEASE_PCSL_STRING_DATA_AND_LENGTH
    if (noerror) {
        return (KNI_IsNullHandle((jobject)*entry) == KNI_TRUE)
               ? KNI_FALSE : KNI_TRUE;
    } else {
        return KNI_FALSE;
    }
}
コード例 #12
0
ファイル: pcsl_rmfs.c プロジェクト: Sektor/phoneme-qtopia
/**
 * The rename function updates the filename.
 */
int pcsl_file_rename(const pcsl_string * oldName, 
		     const pcsl_string * newName)
{
    int status;
    const jbyte * pszOldFilename = pcsl_string_get_utf8_data(oldName);

    if (pszOldFilename == NULL) {
	return -1;
    } else {
      const jbyte * pszNewFilename = pcsl_string_get_utf8_data(newName);

      if (pszNewFilename == NULL) {
	pcsl_string_release_utf8_data(pszOldFilename, oldName);
	return -1;
      }

      status = rmfsRename(pszOldFilename, pszNewFilename);

      pcsl_string_release_utf8_data(pszOldFilename, oldName);
      pcsl_string_release_utf8_data(pszNewFilename, newName);

      return status;
    }
}
コード例 #13
0
ファイル: pcsl_dir_posix.c プロジェクト: jiangxilong/yari
/**
 * The function deletes the directory named dirName from the persistent storage.
 */
int pcsl_file_rmdir(const pcsl_string * dirName)
{
    int   status     = -1;
    const jbyte * pszDirName = pcsl_string_get_utf8_data(dirName);

    if (pszDirName == NULL) {
      return -1;
    }

    status = rmdir((char*)pszDirName);

    pcsl_string_release_utf8_data(pszDirName, dirName);

    return status;
}
コード例 #14
0
ファイル: pcsl_dir_posix.c プロジェクト: jiangxilong/yari
/**
 * Creates the directory with specified name.
 */
int pcsl_file_mkdir(const pcsl_string * dirName)
{    
    int   res          = -1;
    const jbyte * pszOsDirName = pcsl_string_get_utf8_data(dirName);

    if (pszOsDirName == NULL) {
      return -1;
    }

    res = mkdir((char*)pszOsDirName, DEFAULT_DIR_CREATION_MODE);

    pcsl_string_release_utf8_data(pszOsDirName, dirName);
    
    return res;
}
コード例 #15
0
ファイル: pcsl_rmfs.c プロジェクト: Sektor/phoneme-qtopia
/**
 * Check if the file exists in FS storage.
 */
int pcsl_file_exist(const pcsl_string * fileName)
{
    int status;
    const jbyte * pszOsFilename = pcsl_string_get_utf8_data(fileName);

    if (pszOsFilename == NULL) {
	return -1;
    }

    rmfsFileExist(pszOsFilename, &status);

    pcsl_string_release_utf8_data(pszOsFilename, fileName);

    return status;
}
コード例 #16
0
ファイル: pcsl_armsd.c プロジェクト: jiangxilong/yari
/**
 * The unlink function deletes the file named filename from the persistent storage.
 */
int pcsl_file_unlink(const pcsl_string * fileName)
{
    int status;
    const jbyte * pszOsFilename = pcsl_string_get_utf8_data(fileName);

    if (pszOsFilename == NULL) {
      return -1;
    }

    status = remove((char*)pszOsFilename);

    pcsl_string_release_utf8_data(pszOsFilename, fileName);

    return status;
}
コード例 #17
0
ファイル: pcsl_posix.c プロジェクト: sfsy1989/j2me
/**
 * The opendir function opens directory named dirname.
 */
void* pcsl_file_opendir(const pcsl_string * dirName)
{
    DIR* dir;
    const jbyte * pszOsFilename = pcsl_string_get_utf8_data(dirName);

    if (pszOsFilename == NULL) {
      return NULL;
    }

    dir = opendir((char*)pszOsFilename);

    pcsl_string_release_utf8_data(pszOsFilename, dirName);

    return dir;

}
コード例 #18
0
/**
 * The open function creates and returns a new file identifier for the 
 * file named by filename. Initially, the file position indicator for the 
 * file is at the beginning of the file.
 * 
 */
int pcsl_file_open(const pcsl_string * fileName, int flags, void **handle)
{
    int   fd;
    int oFlag = O_RDONLY;
    int   creationMode = 0;
    const jbyte * pszOsFilename = pcsl_string_get_utf8_data(fileName);

    if (pszOsFilename == NULL) {
      return -1;
    }

    /* compute open control flag */
    if ((flags & PCSL_FILE_O_WRONLY) == PCSL_FILE_O_WRONLY) {
        oFlag |= O_WRONLY;
    } 

    if ((flags & PCSL_FILE_O_RDWR) == PCSL_FILE_O_RDWR) {
        oFlag |= O_RDWR;
    } 

    if ((flags & PCSL_FILE_O_CREAT) == PCSL_FILE_O_CREAT) {
        oFlag |= O_CREAT;
        creationMode = DEFAULT_FILE_CREATION_MODE;
    } 

    if ((flags & PCSL_FILE_O_TRUNC) == PCSL_FILE_O_TRUNC) {
        oFlag |= O_TRUNC;
    } 

    if ((flags & PCSL_FILE_O_APPEND) == PCSL_FILE_O_APPEND) {
        oFlag |= O_APPEND;
    }

    fd = open((char*)pszOsFilename, oFlag, creationMode);

    pcsl_string_release_utf8_data(pszOsFilename, fileName);

    if (fd < 0) {
        *handle = NULL;
        return -1;
    }

    *handle = (void *)fd;
    return 0;
}
コード例 #19
0
ファイル: midpDebug.c プロジェクト: Sektor/phoneme-qtopia
void
printPcslStringImpl(const pcsl_string* pstr) {
    if (pcsl_string_length(pstr) <= 0) {
       REPORT_INFO(LC_MIDPSTRING,
		    "printPcslString: Bad Length.");
        return;
    }
    if (pcsl_string_length(pstr) > 0) {
        const char* msg = pcsl_string_get_utf8_data(pstr);
        if (msg) {
	        REPORT_INFO1(LC_MIDPSTRING, "%s", msg);
            pcsl_string_release_utf8_data(msg, pstr);
        } else {
             REPORT_INFO(LC_MIDPSTRING,
	        "printPcslString: can't convert from pcsl_string to char");

        }
    }
}
コード例 #20
0
ファイル: pcsl_dir_posix.c プロジェクト: jiangxilong/yari
/**
 * The getTotalSize function checks the total space in storage.
 */
long pcsl_file_gettotalsize(const pcsl_string * path)
{
    struct statvfs sbuf;
    long  totalBytes = -1; /* -1 if the file system is not accessible*/
    int   status     = -1;
    const jbyte * pszPath = pcsl_string_get_utf8_data(path);

    if (pszPath == NULL) {
      return -1;
    }
    
    status = statvfs((char*)pszPath, &sbuf);
    if (status == 0)
    {
        totalBytes = sbuf.f_bsize * sbuf.f_blocks;
    }
    
    pcsl_string_release_utf8_data(pszPath, path);

    return totalBytes;
}
コード例 #21
0
ファイル: pcsl_dir_posix.c プロジェクト: jiangxilong/yari
/**
 * The function returns value of the attribute for the specified file.
 */
int pcsl_file_get_attribute(const pcsl_string * fileName, int type, int* result)
{
    struct stat sbuf;
    int   status = -1;
    const jbyte * pszName = pcsl_string_get_utf8_data(fileName);

    if (pszName == NULL) {
      return -1;
    }
    
    *result = 0;
    
    status = stat((char*)pszName, &sbuf);

    pcsl_string_release_utf8_data(pszName, fileName);
        
    if (status == 0)
    {
        switch (type) {
        case PCSL_FILE_ATTR_READ:
            *result = (sbuf.st_mode & S_IRUSR) ? 1 : 0;
            break;
        case PCSL_FILE_ATTR_WRITE:
            *result = (sbuf.st_mode & S_IWUSR) ? 1 : 0;
            break;
        case PCSL_FILE_ATTR_EXECUTE:
            *result = (sbuf.st_mode & S_IXUSR) ? 1 : 0;
            break;
        case PCSL_FILE_ATTR_HIDDEN:
            *result = 0;
            break;
        default:
            return -1;
        }        
        return 0;
    }
    
    return -1;
}
コード例 #22
0
ファイル: pcsl_dir_posix.c プロジェクト: jiangxilong/yari
/**
 * Check if the directory exists in FS storage.
 */
int pcsl_file_is_directory(const pcsl_string * path)
{
    struct stat stat_buf;
    int   status  = -1;
    const jbyte * pszName = pcsl_string_get_utf8_data(path);

    if (pszName == NULL) {
      return -1;
    }
 
    status = stat((char*)pszName, &stat_buf);

    pcsl_string_release_utf8_data(pszName, path);

    if (status >= 0 && S_ISDIR(stat_buf.st_mode)) {
        /* stat completed without error and it is a directory */
        return 1;
    }

    /* either stat completed with error or it is not a directory */
    return 0;
}
コード例 #23
0
ファイル: pcsl_posix.c プロジェクト: sfsy1989/j2me
/**
 * Check if the file exists in FS storage.
 */
int pcsl_file_exist(const pcsl_string * fileName)
{
    struct stat stat_buf;
    int status;
    const jbyte * pszOsFilename = pcsl_string_get_utf8_data(fileName);

    if (pszOsFilename == NULL) {
      return 0;
    }
 
    status = stat((char*)pszOsFilename, &stat_buf);

    pcsl_string_release_utf8_data(pszOsFilename, fileName);

    if (status >= 0 && S_ISREG(stat_buf.st_mode)) {
        /* stat completed without error and it is a file */
        return 1;
    }

    /* either stat completed with error or it is not a file */
    return 0;
}
コード例 #24
0
ファイル: pcsl_rmfs.c プロジェクト: Sektor/phoneme-qtopia
/* The getNextEntry function search the next file which is  specified DIR */
int pcsl_file_getnextentry(void *handle, const pcsl_string * string, 
                           pcsl_string * result)
{
    char *pszFilename; /* name of result */
    int len;
    const jbyte * pszMatch = pcsl_string_get_utf8_data(string);

    if (NULL == pszMatch) {
	return -1;
    }

    if (result == NULL) {
      pcsl_string_release_utf8_data(pszMatch, string);
      return -1;
    }

    pszFilename = rmfsFileStartWith(pszMatch);

    pcsl_string_release_utf8_data(pszMatch, string);

    if (NULL == pszFilename) {
      * result = PCSL_STRING_NULL;
      /* End of Dir without a match. */
      return -1;
    }

    len = strlen(pszFilename);

    if (pcsl_string_convert_from_utf8(pszFilename, len, result) != 
	PCSL_STRING_OK) {
      * result = PCSL_STRING_NULL;
      return -1;
    }

    return 0;
}
コード例 #25
0
ファイル: midpMountedRoots.cpp プロジェクト: sfsy1989/j2me
void MidpMountedRoots::update(bool notify)
{
    DEBUG_PRINT("update");

#ifdef UNIX
    QValueList<QString> disks;
    QValueList<QString> paths;
    bool rebuild = false;
    int  count   = 0;

    // Read system mounts
    struct mntent *me;
    FILE *mntfp = setmntent("/etc/mtab", "r");
    if (mntfp)
    {
        while ((me = getmntent( mntfp )) != 0)
        {
            QString disk = me->mnt_fsname;
            if (isValidDisk(disk))
            {
                count++;

                disks.append(disk);

                QString path = QString(me->mnt_dir) + '/';
                paths.append(path);

                if (!isCachedDisk(disk))
                {
                    rebuild = true;
                }
            }
        }
        endmntent(mntfp);
    }

    // Add special roots for PIM, FC and Private
    const pcsl_string* storage = storage_get_root(INTERNAL_STORAGE_ID);
    if (pcsl_string_length(storage) >= 0)
    {
        const char* cstorage = (const char*)pcsl_string_get_utf8_data(storage);
        QString qstorage = cstorage;
        pcsl_string_release_utf8_data((const jbyte*)cstorage, storage);

        QString fc = qstorage + "storage/";
        QFile ffc(fc);
        // determine whether the path exists
        // Note: the path is created by the build system.
        if (ffc.exists())
        {
            count++;
            const QString name = "storage";

            disks.append(name);
            paths.append(fc);

            if (!isCachedDisk(name))
            {
                rebuild = true;
            }
        }

        QString pim = qstorage + "pimdb/";
        QFile fpim(pim);
        // determine whether the path exists
        // Note: the path is created by the build system.
        if (fpim.exists())
        {
            count++;
            const QString name = "pimdb";

            disks.append(name);
            paths.append(pim);

            if (!isCachedDisk(name))
            {
                rebuild = true;
            }
        }

        QString prv = qstorage + "private/";
        QFile fprv(prv);
        // determine whether the path exists
        // Note: the path is created by the build system.
        if (fprv.exists())
        {
            count++;
            const QString name = "private";

            disks.append(name);
            paths.append(prv);

            if (!isCachedDisk(name))
            {
                rebuild = true;
            }
        }
    }

    if (rebuild || count != (int)mRoots.count())
    {
        mRoots.clear();
        QStringList::ConstIterator it  = disks.begin();
        QStringList::ConstIterator pit = paths.begin();
        for (; it != disks.end(); ++it, ++pit)
        {
            QString disk = *it;
            QString path = *pit;
            QString root, local;
            if (getDiskInfo(disk, root, local))
            {
                MidpFileRoot* fs = new MidpFileRoot(disk, path, root, local);
                mRoots.append(fs);
            }
        }
        // Call the handler if required
        if (notify) {
            disksChanged();
        }
    }
#endif
}
コード例 #26
0
ファイル: pcsl_dir_posix.c プロジェクト: jiangxilong/yari
/**
 * The function sets value of the attribute for the specified file.
 */
int pcsl_file_set_attribute(const pcsl_string * fileName, int type, int value)
{
    struct stat sbuf;
    int   status   = -1;    
    int   newmode  = 0;
    int   modeMask = 0;
    int   result   = -1;
    const jbyte * pszName = pcsl_string_get_utf8_data(fileName);

    if (pszName == NULL) {
      return -1;
    }

    status = stat((char*)pszName, &sbuf);    
        
    while (status == 0)
    {        
        switch (type) {
        case PCSL_FILE_ATTR_READ:            
            modeMask = S_IRUSR;
            break;
        case PCSL_FILE_ATTR_WRITE:
            modeMask = S_IWUSR;
            break;
        case PCSL_FILE_ATTR_EXECUTE:
            modeMask = S_IXUSR;
            break;
        case PCSL_FILE_ATTR_HIDDEN:
            result = 0;
            status = -1;
            break;
        default:
            status = -1;
        }

        if (status != 0) {
            break;
        }
        
        if (value) {
            newmode =  modeMask | sbuf.st_mode;
        } else {
            newmode = ~modeMask & sbuf.st_mode;
        }        
        

        /* do not update file attributes if they are not changed */        
        if (newmode == sbuf.st_mode) {
            result = 0;
            break;
        }

        status = chmod((char*)pszName, newmode);        
        if (status != -1) {
            result = 0;
        }
        break;
    }
    
    pcsl_string_release_utf8_data(pszName, fileName);
    return result;
}
コード例 #27
0
ファイル: pcsl_posix.c プロジェクト: sfsy1989/j2me
/** 
    The getNextEntry function search the next file which is specified DIR
 */
int pcsl_file_getnextentry(void *handle, const pcsl_string * string, 
                           pcsl_string * result)
{
    pcsl_string rootpath = PCSL_STRING_NULL;
    pcsl_string returnVal = PCSL_STRING_NULL;
    pcsl_string matchName = PCSL_STRING_NULL;
    jsize matchLen;
    jsize len;
    struct dirent *de;
    char* pszFilename = NULL;
    DIR *dir;
    jsize savedRootLength = 0;
    jsize savedMatchLength = 0;

    PCSLStorageDirInfo* pPCSLStorageDirInfo = (PCSLStorageDirInfo *)handle;
    if (pPCSLStorageDirInfo == NULL) {
        return -1;
    }

    savedRootLength = pPCSLStorageDirInfo->savedRootLength;
    savedMatchLength = pPCSLStorageDirInfo->savedMatchLength;

    if (pcsl_string_substring(string, savedRootLength, 
			      savedRootLength + savedMatchLength,
			      &matchName) != PCSL_STRING_OK) {
      return -1;
    }

    {
      const jbyte * pszMatch = NULL;
      
      dir = pPCSLStorageDirInfo->savedDirectory;

      if (dir == NULL) {
        return -1;
      }

      pszMatch = pcsl_string_get_utf8_data(&matchName);
      
      if (pszMatch == NULL) {
	return -1;
      }

      matchLen = strlen((char*)pszMatch);

      /* find the first match file not "." or ".." */

      for (de = readdir(dir); de != NULL; de = readdir(dir)) {

        pszFilename = de->d_name;
        if (strcmp(pszFilename, ".") == 0 ||
            strcmp(pszFilename, "..") == 0) {
            continue;
        }

        if (strncmp(pszFilename, (char*)pszMatch, matchLen) == 0) {
            break;
        }
      }

      pcsl_string_release_utf8_data(pszMatch, &matchName);

      pcsl_string_free(&matchName);

      if (NULL == de) {
        /* End of Dir without a match. */
        return -1;
      }
      len = strlen(pszFilename);

      if (len >= 0) {
	if (pcsl_string_convert_from_utf8((jbyte*)pszFilename, len, &returnVal) != PCSL_STRING_OK) {
	  return -1;
	}

	if (pcsl_string_substring(string, 0, savedRootLength, &rootpath) != PCSL_STRING_OK) {
	  pcsl_string_free(&returnVal);
	  return -1;
	}

	if (pcsl_string_cat(&rootpath, &returnVal, result) != PCSL_STRING_OK) {
	  pcsl_string_free(&returnVal);
	  pcsl_string_free(&rootpath);
	  return -1;
	}

	pcsl_string_free(&returnVal);
	pcsl_string_free(&rootpath);
      }
    }

    return 0;

}