MCPcopy Create free account
hub / github.com/coreutils/coreutils / gobble_file

Function gobble_file

src/ls.c:3313–3630  ·  view source on GitHub ↗

Add a file to the current table of files. Verify that the file exists, and print an error message if it does not. Return the number of blocks that the file occupies. */

Source from the content-addressed store, hash-verified

3311 Verify that the file exists, and print an error message if it does not.
3312 Return the number of blocks that the file occupies. */
3313static uintmax_t
3314gobble_file (char const *name, enum filetype type, ino_t inode,
3315 bool command_line_arg, char const *dirname)
3316{
3317 uintmax_t blocks = 0;
3318 struct fileinfo *f;
3319
3320 /* An inode value prior to gobble_file necessarily came from readdir,
3321 which is not used for command line arguments. */
3322 affirm (! command_line_arg || inode == NOT_AN_INODE_NUMBER);
3323
3324 if (cwd_n_used == cwd_n_alloc)
3325 cwd_file = xpalloc (cwd_file, &cwd_n_alloc, 1, -1, sizeof *cwd_file);
3326
3327 f = &cwd_file[cwd_n_used];
3328 memset (f, '\0', sizeof *f);
3329 f->stat.st_ino = inode;
3330 f->filetype = type;
3331 f->scontext = UNKNOWN_SECURITY_CONTEXT;
3332
3333 f->quoted = -1;
3334 if ((! cwd_some_quoted) && align_variable_outer_quotes)
3335 {
3336 /* Determine if any quoted for padding purposes. */
3337 f->quoted = needs_quoting (name);
3338 if (f->quoted)
3339 cwd_some_quoted = 1;
3340 }
3341
3342 bool check_stat =
3343 (command_line_arg
3344 || print_hyperlink
3345 || format_needs_stat
3346 || (format_needs_type && type == unknown)
3347 /* When coloring a directory, stat it to indicate
3348 sticky and/or other-writable attributes. */
3349 || ((type == directory || type == unknown) && print_with_color
3350 && (is_colored (C_OTHER_WRITABLE)
3351 || is_colored (C_STICKY)
3352 || is_colored (C_STICKY_OTHER_WRITABLE)))
3353 /* When dereferencing symlinks, the inode and type must come from
3354 stat, but readdir provides the inode and type of lstat. */
3355 || ((print_inode || format_needs_type)
3356 && (type == symbolic_link || type == unknown)
3357 && (dereference == DEREF_ALWAYS
3358 || color_symlink_as_referent || check_symlink_mode))
3359 /* Command line dereferences are already taken care of by the above
3360 assertion that the inode number is not yet known. */
3361 || (print_inode && inode == NOT_AN_INODE_NUMBER)
3362 /* --indicator-style=classify (aka -F) requires statting each
3363 regular file to see whether it's executable. */
3364 || ((type == normal || type == unknown)
3365 && (indicator_style == classify
3366 /* This is so that --color ends up highlighting files with these
3367 mode bits set even when options like -F are not specified. */
3368 || (print_with_color && (is_colored (C_EXEC)
3369 || is_colored (C_SETUID)
3370 || is_colored (C_SETGID))))));

Callers 2

mainFunction · 0.85
print_dirFunction · 0.85

Calls 14

needs_quotingFunction · 0.85
is_coloredFunction · 0.85
attachFunction · 0.85
file_failureFunction · 0.85
do_lstatFunction · 0.85
file_has_aclinfo_cacheFunction · 0.85
is_ENOTSUPFunction · 0.85
has_capability_cacheFunction · 0.85
get_link_nameFunction · 0.85
stat_for_modeFunction · 0.85
format_user_widthFunction · 0.85
format_group_widthFunction · 0.85

Tested by

no test coverage detected