Print this page
667 cp support for -a flag


 165                 (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES),
 166                     strerror(errno));
 167                 exit(3);
 168         }
 169 
 170         if (EQ(cmd, "mv"))
 171                 mve = TRUE;
 172         else if (EQ(cmd, "ln"))
 173                 lnk = TRUE;
 174         else if (EQ(cmd, "cp"))
 175                 cpy = TRUE;
 176         else {
 177                 (void) fprintf(stderr,
 178                     gettext("Invalid command name (%s); expecting "
 179                     "mv, cp, or ln.\n"), cmd);
 180                 exit(1);
 181         }
 182 
 183         /*
 184          * Check for options:
 185          *      cp  -r|-R [-H|-L|-P] [-fip@/] file1 [file2 ...] target
 186          *      cp [-fiprR@/] file1 [file2 ...] target
 187          *      ln [-f] [-n] [-s] file1 [file2 ...] target
 188          *      ln [-f] [-n] [-s] file1 [file2 ...]
 189          *      mv [-f|i] file1 [file2 ...] target
 190          *      mv [-f|i] dir1 target
 191          */
 192 
 193         if (cpy) {
 194                 while ((c = getopt(argc, argv, "fHiLpPrR@/")) != EOF)
 195                         switch (c) {
 196                         case 'f':
 197                                 fflg++;
 198                                 break;
 199                         case 'i':
 200                                 iflg++;
 201                                 break;
 202                         case 'p':
 203                                 pflg++;
 204 #ifdef XPG4
 205                                 attrsilent = 1;
 206                                 atflg = 0;
 207                                 saflg = 0;
 208 #else
 209                                 if (atflg == 0)
 210                                         attrsilent = 1;
 211 #endif
 212                                 break;
 213                         case 'H':
 214                                 /*


 221                                 break;
 222                         case 'L':
 223                                 Hflg = Pflg = 0;
 224                                 Lflg++;
 225                                 break;
 226                         case 'P':
 227                                 Lflg = Hflg = 0;
 228                                 Pflg++;
 229                                 break;
 230                         case 'R':
 231                                 /*
 232                                  * The default behavior of cp -R|-r
 233                                  * when specified without -H|-L|-P
 234                                  * is -L.
 235                                  */
 236                                 Rflg++;
 237                                 /*FALLTHROUGH*/
 238                         case 'r':
 239                                 rflg++;
 240                                 break;







 241                         case '@':
 242                                 atflg++;
 243                                 attrsilent = 0;
 244 #ifdef XPG4
 245                                 pflg = 0;
 246 #endif
 247                                 break;
 248                         case '/':
 249                                 saflg++;
 250                                 attrsilent = 0;
 251 #ifdef XPG4
 252                                 pflg = 0;
 253 #endif
 254                                 break;
 255                         default:
 256                                 errflg++;
 257                         }
 258 
 259                 /* -R or -r must be specified with -H, -L, or -P */
 260                 if ((Hflg || Lflg || Pflg) && !(Rflg || rflg)) {


1306 
1307         if (mve) {
1308                 (void) fprintf(stderr, gettext(
1309                     "Usage: mv [-f] [-i] f1 f2\n"
1310                     "       mv [-f] [-i] f1 ... fn d1\n"
1311                     "       mv [-f] [-i] d1 d2\n"));
1312         } else if (lnk) {
1313 #ifdef XPG4
1314                 (void) fprintf(stderr, gettext(
1315                     "Usage: ln [-f] [-s] f1 [f2]\n"
1316                     "       ln [-f] [-s] f1 ... fn d1\n"
1317                     "       ln [-f] -s d1 d2\n"));
1318 #else
1319                 (void) fprintf(stderr, gettext(
1320                     "Usage: ln [-f] [-n] [-s] f1 [f2]\n"
1321                     "       ln [-f] [-n] [-s] f1 ... fn d1\n"
1322                     "       ln [-f] [-n] -s d1 d2\n"));
1323 #endif
1324         } else if (cpy) {
1325                 (void) fprintf(stderr, gettext(
1326                     "Usage: cp [-f] [-i] [-p] [-@] [-/] f1 f2\n"
1327                     "       cp [-f] [-i] [-p] [-@] [-/] f1 ... fn d1\n"
1328                     "       cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] [-/] "
1329                     "d1 ... dn-1 dn\n"));
1330         }
1331         exit(2);
1332 }
1333 
1334 /*
1335  * chg_time()
1336  *
1337  * Try to preserve modification and access time.
1338  * If 1) pflg is not set, or 2) pflg is set and this is the Solaris version,
1339  * don't report a utimensat() failure.
1340  * If this is the XPG4 version and utimensat fails, if 1) pflg is set (cp -p)
1341  * or 2) we are doing a mv, print a diagnostic message; arrange for a non-zero
1342  * exit status only if pflg is set.
1343  * utimensat(2) is being used to achieve granularity in nanoseconds
1344  * (if supported by the underlying file system) while setting file times.
1345  */
1346 static int
1347 chg_time(char *to, struct stat ss)
1348 {
1349         struct timespec times[2];




 165                 (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES),
 166                     strerror(errno));
 167                 exit(3);
 168         }
 169 
 170         if (EQ(cmd, "mv"))
 171                 mve = TRUE;
 172         else if (EQ(cmd, "ln"))
 173                 lnk = TRUE;
 174         else if (EQ(cmd, "cp"))
 175                 cpy = TRUE;
 176         else {
 177                 (void) fprintf(stderr,
 178                     gettext("Invalid command name (%s); expecting "
 179                     "mv, cp, or ln.\n"), cmd);
 180                 exit(1);
 181         }
 182 
 183         /*
 184          * Check for options:
 185          *      cp [ -r|-R [-H|-L|-P]] [-afip@/] file1 [file2 ...] target
 186          *      cp [-afiprR@/] file1 [file2 ...] target
 187          *      ln [-f] [-n] [-s] file1 [file2 ...] target
 188          *      ln [-f] [-n] [-s] file1 [file2 ...]
 189          *      mv [-f|i] file1 [file2 ...] target
 190          *      mv [-f|i] dir1 target
 191          */
 192 
 193         if (cpy) {
 194                 while ((c = getopt(argc, argv, "afHiLpPrR@/")) != EOF)
 195                         switch (c) {
 196                         case 'f':
 197                                 fflg++;
 198                                 break;
 199                         case 'i':
 200                                 iflg++;
 201                                 break;
 202                         case 'p':
 203                                 pflg++;
 204 #ifdef XPG4
 205                                 attrsilent = 1;
 206                                 atflg = 0;
 207                                 saflg = 0;
 208 #else
 209                                 if (atflg == 0)
 210                                         attrsilent = 1;
 211 #endif
 212                                 break;
 213                         case 'H':
 214                                 /*


 221                                 break;
 222                         case 'L':
 223                                 Hflg = Pflg = 0;
 224                                 Lflg++;
 225                                 break;
 226                         case 'P':
 227                                 Lflg = Hflg = 0;
 228                                 Pflg++;
 229                                 break;
 230                         case 'R':
 231                                 /*
 232                                  * The default behavior of cp -R|-r
 233                                  * when specified without -H|-L|-P
 234                                  * is -L.
 235                                  */
 236                                 Rflg++;
 237                                 /*FALLTHROUGH*/
 238                         case 'r':
 239                                 rflg++;
 240                                 break;
 241                         case 'a':
 242                                 Lflg = Hflg = 0;
 243                                 pflg++;
 244                                 Pflg++;
 245                                 Rflg++;
 246                                 rflg++;
 247                                 break;
 248                         case '@':
 249                                 atflg++;
 250                                 attrsilent = 0;
 251 #ifdef XPG4
 252                                 pflg = 0;
 253 #endif
 254                                 break;
 255                         case '/':
 256                                 saflg++;
 257                                 attrsilent = 0;
 258 #ifdef XPG4
 259                                 pflg = 0;
 260 #endif
 261                                 break;
 262                         default:
 263                                 errflg++;
 264                         }
 265 
 266                 /* -R or -r must be specified with -H, -L, or -P */
 267                 if ((Hflg || Lflg || Pflg) && !(Rflg || rflg)) {


1313 
1314         if (mve) {
1315                 (void) fprintf(stderr, gettext(
1316                     "Usage: mv [-f] [-i] f1 f2\n"
1317                     "       mv [-f] [-i] f1 ... fn d1\n"
1318                     "       mv [-f] [-i] d1 d2\n"));
1319         } else if (lnk) {
1320 #ifdef XPG4
1321                 (void) fprintf(stderr, gettext(
1322                     "Usage: ln [-f] [-s] f1 [f2]\n"
1323                     "       ln [-f] [-s] f1 ... fn d1\n"
1324                     "       ln [-f] -s d1 d2\n"));
1325 #else
1326                 (void) fprintf(stderr, gettext(
1327                     "Usage: ln [-f] [-n] [-s] f1 [f2]\n"
1328                     "       ln [-f] [-n] [-s] f1 ... fn d1\n"
1329                     "       ln [-f] [-n] -s d1 d2\n"));
1330 #endif
1331         } else if (cpy) {
1332                 (void) fprintf(stderr, gettext(
1333                     "Usage: cp [-a] [-f] [-i] [-p] [-@] [-/] f1 f2\n"
1334                     "       cp [-a] [-f] [-i] [-p] [-@] [-/] f1 ... fn d1\n"
1335                     "       cp [-r|-R [-H|-L|-P]] [-a] [-f] [-i] [-p] [-@] "
1336                     "[-/] d1 ... dn-1 dn\n"));
1337         }
1338         exit(2);
1339 }
1340 
1341 /*
1342  * chg_time()
1343  *
1344  * Try to preserve modification and access time.
1345  * If 1) pflg is not set, or 2) pflg is set and this is the Solaris version,
1346  * don't report a utimensat() failure.
1347  * If this is the XPG4 version and utimensat fails, if 1) pflg is set (cp -p)
1348  * or 2) we are doing a mv, print a diagnostic message; arrange for a non-zero
1349  * exit status only if pflg is set.
1350  * utimensat(2) is being used to achieve granularity in nanoseconds
1351  * (if supported by the underlying file system) while setting file times.
1352  */
1353 static int
1354 chg_time(char *to, struct stat ss)
1355 {
1356         struct timespec times[2];