MCPcopy Create free account
hub / github.com/git/git / get_dtype

Function get_dtype

dir.c:2335–2366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2333}
2334
2335unsigned char get_dtype(struct dirent *e, struct strbuf *path,
2336 int follow_symlink)
2337{
2338 struct stat st;
2339 unsigned char dtype = DTYPE(e);
2340 size_t base_path_len;
2341
2342 if (dtype != DT_UNKNOWN && !(follow_symlink && dtype == DT_LNK))
2343 return dtype;
2344
2345 /*
2346 * d_type unknown or unfollowed symlink, try to fall back on [l]stat
2347 * results. If [l]stat fails, explicitly set DT_UNKNOWN.
2348 */
2349 base_path_len = path->len;
2350 strbuf_addstr(path, e->d_name);
2351 if ((follow_symlink && stat(path->buf, &st)) ||
2352 (!follow_symlink && lstat(path->buf, &st)))
2353 goto cleanup;
2354
2355 /* determine d_type from st_mode */
2356 if (S_ISREG(st.st_mode))
2357 dtype = DT_REG;
2358 else if (S_ISDIR(st.st_mode))
2359 dtype = DT_DIR;
2360 else if (S_ISLNK(st.st_mode))
2361 dtype = DT_LNK;
2362
2363cleanup:
2364 strbuf_setlen(path, base_path_len);
2365 return dtype;
2366}
2367
2368static int resolve_dtype(int dtype, struct index_state *istate,
2369 const char *path, int len)

Callers 7

for_each_file_in_dirFunction · 0.85
read_directory_contentsFunction · 0.85
count_filesFunction · 0.85
loose_objs_statsFunction · 0.85
loose_fill_ref_dirFunction · 0.85
for_each_root_refFunction · 0.85

Calls 3

strbuf_addstrFunction · 0.85
strbuf_setlenFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected