[BACK]Return to sort.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / sort

Diff for /src/usr.bin/sort/sort.c between version 1.82 and 1.83

version 1.82, 2015/10/14 16:42:51 version 1.83, 2015/10/17 14:33:01
Line 868 
Line 868 
         bool mef_flags[NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS] =          bool mef_flags[NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS] =
             { false, false, false, false, false, false };              { false, false, false, false, false, false };
   
           set_hw_params();
   
           if (pledge("stdio rpath wpath cpath fattr proc exec", NULL) == -1)
                   err(2, "pledge");
   
         outfile = "-";          outfile = "-";
         real_outfile = NULL;          real_outfile = NULL;
         sflag = NULL;          sflag = NULL;
Line 878 
Line 883 
   
         atexit(clear_tmp_files);          atexit(clear_tmp_files);
   
         set_hw_params();  
         set_locale();          set_locale();
         set_tmpdir();          set_tmpdir();
         set_sort_opts();          set_sort_opts();
Line 1048 
Line 1052 
         argc -= optind;          argc -= optind;
         argv += optind;          argv += optind;
   
           if (compress_program == NULL) {
                   if (pledge("stdio rpath wpath cpath fattr", NULL) == -1)
                           err(2, "pledge");
           }
   
 #ifndef GNUSORT_COMPATIBILITY  #ifndef GNUSORT_COMPATIBILITY
         if (argc > 2 && strcmp(argv[argc - 2], "-o") == 0) {          if (argc > 2 && strcmp(argv[argc - 2], "-o") == 0) {
                 outfile = argv[argc - 1];                  outfile = argv[argc - 1];
Line 1060 
Line 1069 
                 argv = argv_from_file0;                  argv = argv_from_file0;
         }          }
   
         if (sort_opts_vals.cflag && argc > 1)          if (sort_opts_vals.cflag) {
                 errx(2, "only one input file is allowed with the -%c flag",                  if (argc > 1)
                     sort_opts_vals.csilentflag ? 'C' : 'c');                          errx(2, "only one input file is allowed with the -%c flag",
                               sort_opts_vals.csilentflag ? 'C' : 'c');
   
                   if (argc == 0 || strcmp(argv[0], "-") == 0) {
                           if (compress_program) {
                                   if (pledge("stdio proc exec", NULL) == -1)
                                           err(2, "pledge");
                           } else {
                                   if (pledge("stdio", NULL) == -1)
                                           err(2, "pledge");
                           }
                   } else {
                           if (compress_program) {
                                   if (pledge("stdio rpath proc exec", NULL) == -1)
                                           err(2, "pledge");
                           } else {
                                   if (pledge("stdio rpath", NULL) == -1)
                                           err(2, "pledge");
                           }
                   }
           } else {
                   /* Case when the outfile equals one of the input files: */
                   if (strcmp(outfile, "-") != 0) {
                           struct stat sb;
                           int fd, i;
   
                           for (i = 0; i < argc; ++i) {
                                   if (strcmp(argv[i], outfile) == 0) {
                                           if (stat(outfile, &sb) == -1)
                                                   err(2, "%s", outfile);
                                           if (access(outfile, W_OK) == -1)
                                                   err(2, "%s", outfile);
                                           real_outfile = outfile;
                                           sort_asprintf(&outfile, "%s.XXXXXXXXXX",
                                               real_outfile);
                                           if ((fd = mkstemp(outfile)) == -1)
                                                   err(2, "mkstemp: %s", outfile);
                                           if (fchown(fd, sb.st_uid, sb.st_gid) == -1)
                                                   warn("unable to set ownership of %s",
                                                       outfile);
                                           if (fchmod(fd, sb.st_mode & ACCESSPERMS) == -1)
                                                   err(2, "fchmod: %s", outfile);
                                           close(fd);
                                           tmp_file_atexit(outfile);
                                           break;
                                   }
                           }
                   }
   
                   if (compress_program) {
                           if (pledge("stdio rpath wpath cpath proc exec", NULL) == -1)
                                   err(2, "pledge");
                   } else {
                           if (pledge("stdio rpath wpath cpath", NULL) == -1)
                                   err(2, "pledge");
                   }
           }
   
         if (sflag != NULL)          if (sflag != NULL)
                 available_free_memory = parse_memory_buffer_value(sflag);                  available_free_memory = parse_memory_buffer_value(sflag);
   
Line 1117 
Line 1182 
                 return check(argc ? *argv : "-");                  return check(argc ? *argv : "-");
   
         set_random_seed();          set_random_seed();
   
         /* Case when the outfile equals one of the input files: */  
         if (strcmp(outfile, "-") != 0) {  
                 struct stat sb;  
                 int fd, i;  
   
                 for (i = 0; i < argc; ++i) {  
                         if (strcmp(argv[i], outfile) == 0) {  
                                 if (stat(outfile, &sb) == -1)  
                                         err(2, "%s", outfile);  
                                 if (access(outfile, W_OK) == -1)  
                                         err(2, "%s", outfile);  
                                 real_outfile = outfile;  
                                 sort_asprintf(&outfile, "%s.XXXXXXXXXX",  
                                     real_outfile);  
                                 if ((fd = mkstemp(outfile)) == -1)  
                                         err(2, "mkstemp: %s", outfile);  
                                 if (fchown(fd, sb.st_uid, sb.st_gid) == -1)  
                                         warn("unable to set ownership of %s",  
                                             outfile);  
                                 if (fchmod(fd, sb.st_mode & ACCESSPERMS) == -1)  
                                         err(2, "fchmod: %s", outfile);  
                                 close(fd);  
                                 tmp_file_atexit(outfile);  
                                 break;  
                         }  
                 }  
         }  
   
         if (!sort_opts_vals.mflag) {          if (!sort_opts_vals.mflag) {
                 struct file_list fl;                  struct file_list fl;

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.83