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

Function decode_preserve_arg

src/cp.c:936–1026  ·  view source on GitHub ↗

Given a string, ARG, containing a comma-separated list of arguments to the --preserve option, set the appropriate fields of X to ON_OFF. */

Source from the content-addressed store, hash-verified

934/* Given a string, ARG, containing a comma-separated list of arguments
935 to the --preserve option, set the appropriate fields of X to ON_OFF. */
936static void
937decode_preserve_arg (char const *arg, struct cp_options *x, bool on_off)
938{
939 enum File_attribute
940 {
941 PRESERVE_MODE,
942 PRESERVE_TIMESTAMPS,
943 PRESERVE_OWNERSHIP,
944 PRESERVE_LINK,
945 PRESERVE_CONTEXT,
946 PRESERVE_XATTR,
947 PRESERVE_ALL
948 };
949 static enum File_attribute const preserve_vals[] =
950 {
951 PRESERVE_MODE, PRESERVE_TIMESTAMPS,
952 PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_CONTEXT, PRESERVE_XATTR,
953 PRESERVE_ALL
954 };
955 /* Valid arguments to the '--preserve' option. */
956 static char const *const preserve_args[] =
957 {
958 "mode", "timestamps",
959 "ownership", "links", "context", "xattr", "all", NULL
960 };
961 ARGMATCH_VERIFY (preserve_args, preserve_vals);
962
963 char *arg_writable = xstrdup (arg);
964 char *s = arg_writable;
965 do
966 {
967 /* find next comma */
968 char *comma = strchr (s, ',');
969 enum File_attribute val;
970
971 /* If we found a comma, put a NUL in its place and advance. */
972 if (comma)
973 *comma++ = 0;
974
975 /* process S. */
976 val = XARGMATCH (on_off ? "--preserve" : "--no-preserve",
977 s, preserve_args, preserve_vals);
978 switch (val)
979 {
980 case PRESERVE_MODE:
981 x->preserve_mode = on_off;
982 x->explicit_no_preserve_mode = !on_off;
983 break;
984
985 case PRESERVE_TIMESTAMPS:
986 x->preserve_timestamps = on_off;
987 break;
988
989 case PRESERVE_OWNERSHIP:
990 x->preserve_ownership = on_off;
991 break;
992
993 case PRESERVE_LINK:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected