Beispiel #1
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    int status     = 0;
    char *filename = NULL;
    structStat stbuf;
    
    if (nrhs != 1)
    {
        mexErrMsgTxt("One input only required.");
    }
    else
    {
        if (!mxIsChar(prhs[0]))
        {
            mexErrMsgTxt("Input must be a string.");
        }
        filename = mxArrayToString(prhs[0]);
        
        if ((getFileStat(filename, &stbuf) == 0) && (S_ISREG(stbuf.st_mode)))
        {
            status = 1;
        }

        mxFree(filename);
    }
        
    plhs[0] = mxCreateLogicalScalar(status);
}
Beispiel #2
0
bool getFileModificationTime(const String& path, time_t& modifiedTime)
{
    GStatBuf statResult;
    if (!getFileStat(path, &statResult))
        return false;

    modifiedTime = statResult.st_mtime;
    return true;
}
Beispiel #3
0
bool getFileSize(const String& path, long long& resultSize)
{
    GStatBuf statResult;
    if (!getFileStat(path, &statResult))
        return false;

    resultSize = statResult.st_size;
    return true;
}
Beispiel #4
0
bool getFileMetadata(const String& path, FileMetadata& metadata)
{
    GStatBuf statResult;
    if (!getFileStat(path, &statResult))
        return false;

    metadata.modificationTime = statResult.st_mtime;
    metadata.length = statResult.st_size;
    metadata.type = S_ISDIR(statResult.st_mode) ? FileMetadata::TypeDirectory : FileMetadata::TypeFile;
    return true;
}
/* see drm_file.h */
int32_t
DRM_file_getFileLength(const uint16_t *name, int32_t nameLen)
{
    struct stat sbuf;

    if (getFileStat(name, nameLen, &sbuf))
    {
        if (sbuf.st_size >= INT32_MAX)
        {
            ALOGD("DRM_file_getFileLength: file too big");
        }
        else /* Successful */
        {
            ALOGD("DRM_file_getFileLength: %.*S -> %d",
                                         nameLen, name, (int32_t)sbuf.st_size);
            return (int32_t)sbuf.st_size;
        }
    }

    return DRM_FILE_FAILURE;
}
/* see drm_file.h */
int32_t
DRM_file_exists(const uint16_t *name, int32_t nameLen)
{
    struct stat sbuf;

    ALOGD("DRM_file_exists: %.*S", nameLen, name);

    /*remove trailing "/" separators, except the first "/" standing for root*/
    while ((nameLen > 1) && (name[nameLen -1] == '/'))
       --nameLen;

    if (getFileStat(name, nameLen, &sbuf))
    {
        ALOGD("DRM_file_exists: stat returns mode 0x%x", sbuf.st_mode);

        if (S_ISDIR(sbuf.st_mode))
            return DRM_FILE_ISDIR;
        if (S_ISREG(sbuf.st_mode))
            return DRM_FILE_ISREG;
    }

    return DRM_FILE_FAILURE;
}
Beispiel #7
0
void put(int value){
  server_request temp = getFileStat(value);
  temp.time = Time_GetSeconds();
  temp.connValue = value;
  temp.size = temp.sbuf.st_size;
  

  structBuffer[fill] = temp;
  fill = (fill + 1) % bufsize;
  count++;
  
  qsort (structBuffer, bufsize, sizeof(server_request), compare);
  int i;
  if(DEBUG){
    printf("\nFILL %d",fill);  
    for(i = 0; i < bufsize; i++){
      printf("\nBuf[%d] Time : %f",i, structBuffer[i].time);
      printf("\nBuf[%d] Value : %d",i, structBuffer[i].connValue);
      printf("\nBuf[%d] Size : %d",i, structBuffer[i].size);
    }
  }

}
/* see drm_file.h */
int32_t
DRM_file_listOpen(const uint16_t *prefix,
                    int32_t prefixLen,
                    int32_t* session,
                    int32_t* iteration)
{
    ALOGD("DRM_file_listOpen: %.*S", prefixLen, prefix);

#if 0
    if (convertFilename(prefix, prefixLen, tmpPathBuf1) <= 0)
    {
        ALOGD("DRM_file_listOpen: bad filename");
    }
    else
    {
#endif
        DIR *dir;

        /* find the last /, and store the offset to the leaf prefix in
         * *iteration
         */
        char *sep = strrchr(prefix, '/');
        /* Root "/" is a leaf */
        if (sep == NULL || ((sep != NULL) && (sep == tmpPathBuf1)))
        {
            *iteration = prefixLen;

#ifdef ALOGD_ON
            sep = " <empty>"; /* ALOGD will show sep+1 */
#endif
        }
        else
        {
            *iteration = sep - tmpPathBuf1 + 1;
            *sep = 0;
        }
        dir = opendir(prefix);

        if (dir == NULL)
        {
            ALOGD("DRM_file_listOpen: opendir %s: errno=%d", prefix, errno);
        }
        else
        {
            ALOGD("DRM_file_listOpen: dir %s, filter %s", prefix, sep+1);
            *session = (int32_t)(long)dir;
            return DRM_FILE_SUCCESS;
        }
    return DRM_FILE_FAILURE;
}

/* see drm_file.h */
int32_t
DRM_file_listNextEntry(const uint16_t *prefix, int32_t prefixLen,
                       uint16_t* entry, int32_t entrySize,
                       int32_t *session, int32_t* iteration)
{
    struct dirent *ent;

    /* We stored the offset of the leaf part of the prefix (if any)
     * in *iteration
     */
    const uint16_t* strData   = prefix + *iteration;
    int32_t   strLength = prefixLen - *iteration;

    /* entrySize is bytes for some reason. Convert to ucs chars */
    entrySize /= 2;

    /* Now we want to filter for files which start with the (possibly empty)
     * sequence at strData. We have to return fully-qualified filenames,
     * which means *iteration characters from prefix, plus the
     * leaf name.
     */

    while ( (ent = readdir((DIR *)(long)*session)) != NULL)
    {
        int len = strlen(ent->d_name);

        if ( (len + *iteration) > entrySize)
        {
            ALOGD("DRM_file_listNextEntry: %s too long", ent->d_name);
        }
        else if (strcmp(ent->d_name, ".") != 0 &&
                 strcmp(ent->d_name, "..") != 0)
        {
            int idx;
            struct stat sinfo;

            /* check against the filter */

            for (idx = 0; idx < strLength; ++idx)
            {
                if (ent->d_name[idx] != strData[idx])
                    goto next_name;
            }

            ALOGD("DRM_file_listNextEntry: matched %s", ent->d_name);

            /* Now generate the fully-qualified name */

            for (idx = 0; idx < *iteration; ++idx)
                entry[idx] = prefix[idx];

            for (idx = 0; idx < len; ++idx)
                entry[*iteration + idx] = (unsigned char)ent->d_name[idx];

            /*add "/" at the end of a DIR file entry*/
            if (getFileStat(entry, idx + *iteration, &sinfo)){
                if (S_ISDIR(sinfo.st_mode) &&
                        (idx + 1 + *iteration) < entrySize) {
                    entry[*iteration + idx] = '/';
                    ++idx;
                }
            }
            else
            {
                ALOGD("DRM_file_listNextEntry: stat FAILURE on %.*S",
                      idx + *iteration, entry);
            }
            ALOGD("DRM_file_listNextEntry: got %.*S", idx + *iteration, entry);

            return idx + *iteration;
        }

    next_name:
        ALOGD("DRM_file_listNextEntry: rejected %s", ent->d_name);
    }

    ALOGD("DRM_file_listNextEntry: end of list");
    return 0;
}

/* see drm_file.h */
int32_t
DRM_file_listClose(int32_t session, int32_t iteration)
{
    closedir( (DIR *)(long)session);
    return DRM_FILE_SUCCESS;
}