MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / file_read_dir

Function file_read_dir

libavformat/file.c:349–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347}
348
349static int file_read_dir(URLContext *h, AVIODirEntry **next)
350{
351#if HAVE_LSTAT
352 FileContext *c = h->priv_data;
353 struct dirent *dir;
354 char *fullpath = NULL;
355
356 *next = ff_alloc_dir_entry();
357 if (!*next)
358 return AVERROR(ENOMEM);
359 do {
360 errno = 0;
361 dir = readdir(c->dir);
362 if (!dir) {
363 av_freep(next);
364 return AVERROR(errno);
365 }
366 } while (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."));
367
368 fullpath = av_append_path_component(h->filename, dir->d_name);
369 if (fullpath) {
370 struct stat st;
371 if (!lstat(fullpath, &st)) {
372 if (S_ISDIR(st.st_mode))
373 (*next)->type = AVIO_ENTRY_DIRECTORY;
374 else if (S_ISFIFO(st.st_mode))
375 (*next)->type = AVIO_ENTRY_NAMED_PIPE;
376 else if (S_ISCHR(st.st_mode))
377 (*next)->type = AVIO_ENTRY_CHARACTER_DEVICE;
378 else if (S_ISBLK(st.st_mode))
379 (*next)->type = AVIO_ENTRY_BLOCK_DEVICE;
380 else if (S_ISLNK(st.st_mode))
381 (*next)->type = AVIO_ENTRY_SYMBOLIC_LINK;
382 else if (S_ISSOCK(st.st_mode))
383 (*next)->type = AVIO_ENTRY_SOCKET;
384 else if (S_ISREG(st.st_mode))
385 (*next)->type = AVIO_ENTRY_FILE;
386 else
387 (*next)->type = AVIO_ENTRY_UNKNOWN;
388
389 (*next)->group_id = st.st_gid;
390 (*next)->user_id = st.st_uid;
391 (*next)->size = st.st_size;
392 (*next)->filemode = st.st_mode & 0777;
393 (*next)->modification_timestamp = INT64_C(1000000) * st.st_mtime;
394 (*next)->access_timestamp = INT64_C(1000000) * st.st_atime;
395 (*next)->status_change_timestamp = INT64_C(1000000) * st.st_ctime;
396 }
397 av_free(fullpath);
398 }
399
400 (*next)->name = av_strdup(dir->d_name);
401 return 0;
402#else
403 return AVERROR(ENOSYS);
404#endif /* HAVE_LSTAT */
405}
406

Callers

nothing calls this directly

Calls 5

ff_alloc_dir_entryFunction · 0.85
av_freepFunction · 0.85
av_append_path_componentFunction · 0.85
av_strdupFunction · 0.85
av_freeFunction · 0.50

Tested by

no test coverage detected