main.c (292588) | main.c (312518) |
---|---|
1/////////////////////////////////////////////////////////////////////////////// 2// 3/// \file main.c 4/// \brief main() 5// 6// Author: Lasse Collin 7// 8// This file has been put into the public domain. --- 191 unchanged lines hidden (view full) --- 200 // It's good to keep signal handlers in normal compression and 201 // decompression modes even when only writing to stdout, because 202 // we might need to restore O_APPEND flag on stdout before exiting. 203 // In --test mode, signal handlers aren't really needed, but let's 204 // keep them there for consistency with normal decompression. 205 if (opt_mode != MODE_LIST) 206 signals_init(); 207 | 1/////////////////////////////////////////////////////////////////////////////// 2// 3/// \file main.c 4/// \brief main() 5// 6// Author: Lasse Collin 7// 8// This file has been put into the public domain. --- 191 unchanged lines hidden (view full) --- 200 // It's good to keep signal handlers in normal compression and 201 // decompression modes even when only writing to stdout, because 202 // we might need to restore O_APPEND flag on stdout before exiting. 203 // In --test mode, signal handlers aren't really needed, but let's 204 // keep them there for consistency with normal decompression. 205 if (opt_mode != MODE_LIST) 206 signals_init(); 207 |
208#ifdef ENABLE_SANDBOX 209 // Set a flag that sandboxing is allowed if all these are true: 210 // - --files or --files0 wasn't used. 211 // - There is exactly one input file or we are reading from stdin. 212 // - We won't create any files: output goes to stdout or --test 213 // or --list was used. Note that --test implies opt_stdout = true 214 // but --list doesn't. 215 // 216 // This is obviously not ideal but it was easy to implement and 217 // it covers the most common use cases. 218 // 219 // TODO: Make sandboxing work for other situations too. 220 if (args.files_name == NULL && args.arg_count == 1 221 && (opt_stdout || strcmp("-", args.arg_names[0]) == 0 222 || opt_mode == MODE_LIST)) 223 io_allow_sandbox(); 224#endif 225 |
|
208 // coder_run() handles compression, decompression, and testing. 209 // list_file() is for --list. | 226 // coder_run() handles compression, decompression, and testing. 227 // list_file() is for --list. |
210 void (*run)(const char *filename) = opt_mode == MODE_LIST 211 ? &list_file : &coder_run; | 228 void (*run)(const char *filename) = &coder_run; 229#ifdef HAVE_DECODERS 230 if (opt_mode == MODE_LIST) 231 run = &list_file; 232#endif |
212 213 // Process the files given on the command line. Note that if no names 214 // were given, args_parse() gave us a fake "-" filename. 215 for (unsigned i = 0; i < args.arg_count && !user_abort; ++i) { 216 if (strcmp("-", args.arg_names[i]) == 0) { 217 // Processing from stdin to stdout. Check that we 218 // aren't writing compressed data to a terminal or 219 // reading it from a terminal. --- 42 unchanged lines hidden (view full) --- 262 assert(name[0] != '\0'); 263 run(name); 264 } 265 266 if (args.files_name != stdin_filename) 267 (void)fclose(args.files_file); 268 } 269 | 233 234 // Process the files given on the command line. Note that if no names 235 // were given, args_parse() gave us a fake "-" filename. 236 for (unsigned i = 0; i < args.arg_count && !user_abort; ++i) { 237 if (strcmp("-", args.arg_names[i]) == 0) { 238 // Processing from stdin to stdout. Check that we 239 // aren't writing compressed data to a terminal or 240 // reading it from a terminal. --- 42 unchanged lines hidden (view full) --- 283 assert(name[0] != '\0'); 284 run(name); 285 } 286 287 if (args.files_name != stdin_filename) 288 (void)fclose(args.files_file); 289 } 290 |
291#ifdef HAVE_DECODERS |
|
270 // All files have now been handled. If in --list mode, display 271 // the totals before exiting. We don't have signal handlers 272 // enabled in --list mode, so we don't need to check user_abort. 273 if (opt_mode == MODE_LIST) { 274 assert(!user_abort); 275 list_totals(); 276 } | 292 // All files have now been handled. If in --list mode, display 293 // the totals before exiting. We don't have signal handlers 294 // enabled in --list mode, so we don't need to check user_abort. 295 if (opt_mode == MODE_LIST) { 296 assert(!user_abort); 297 list_totals(); 298 } |
299#endif |
|
277 278#ifndef NDEBUG 279 coder_free(); 280 args_free(); 281#endif 282 283 // If we have got a signal, raise it to kill the program instead 284 // of calling tuklib_exit(). --- 23 unchanged lines hidden --- | 300 301#ifndef NDEBUG 302 coder_free(); 303 args_free(); 304#endif 305 306 // If we have got a signal, raise it to kill the program instead 307 // of calling tuklib_exit(). --- 23 unchanged lines hidden --- |