Exemple #1
0
/**
 * The getUsedSpace function checks the size of used space by
 * all of the files that are contained in the directory.
 */
long pcsl_file_getusedspace(const pcsl_string * dirName)
{
    DIR *dir;
    long size;
    struct dirent *de;
    struct stat stat_buf;
    char filename[PCSL_FILE_MAX_NAME_LEN + 1];
    int rootLen;
    int exists;

    dir = (DIR *)pcsl_file_opendir(dirName);
    if (dir == NULL) {
        return 0;
    }

    size = 0;

    {
      if (pcsl_string_convert_to_utf8(dirName, (jbyte*)filename, sizeof(filename), NULL)
	  != PCSL_STRING_OK) {
	pcsl_file_closedir(dir);
	return 0;
      }

      rootLen = strlen(filename);
      for (de = readdir(dir); de != NULL;
	   de = readdir(dir), filename[rootLen] = 0) {
        if (strcmp(de->d_name, ".") == 0 ||
            strcmp(de->d_name, "..") == 0) {
	  continue;
        }

        strncat(filename, de->d_name, sizeof (filename) - 1 - rootLen);

        exists = stat(filename, &stat_buf);
        if (exists != -1 && !S_ISDIR(stat_buf.st_mode)) {
            size += stat_buf.st_size;
        }
      }

      pcsl_file_closedir(dir);
      return size;
    }
}
Exemple #2
0
/**
 * The openfilelist function opens filelist 'string' 
 */
void* pcsl_file_openfilelist(const pcsl_string * string)
{
    return pcsl_file_opendir(string);
}