{"record":{"id":"31d93730f62750a5","repo":"DrKLO/Telegram","slug":"error-opening-output-file-s-n","errorCode":null,"errorMessage":"Error opening output file: %s\\n","messagePattern":"Error opening output file: (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/src/repacketizer_demo.c","lineNumber":108,"sourceCode":"      } else if (strcmp(argv[i], \"-split\")==0)\n         split = 1;\n      else\n      {\n         fprintf(stderr, \"Unknown option: %s\\n\", argv[i]);\n         usage(argv[0]);\n         return EXIT_FAILURE;\n      }\n   }\n   fin = fopen(argv[argc-2], \"r\");\n   if(fin==NULL)\n   {\n     fprintf(stderr, \"Error opening input file: %s\\n\", argv[argc-2]);\n     return EXIT_FAILURE;\n   }\n   fout = fopen(argv[argc-1], \"w\");\n   if(fout==NULL)\n   {\n     fprintf(stderr, \"Error opening output file: %s\\n\", argv[argc-1]);\n     fclose(fin);\n     return EXIT_FAILURE;\n   }\n\n   rp = opus_repacketizer_create();\n   while (!eof)\n   {\n      int err;\n      int nb_packets=merge;\n      opus_repacketizer_init(rp);\n      for (i=0;i<nb_packets;i++)\n      {\n         unsigned char ch[4];\n         err = fread(ch, 1, 4, fin);\n         len[i] = char_to_int(ch);\n         /*fprintf(stderr, \"in len = %d\\n\", len[i]);*/\n         if (len[i]>1500 || len[i]<0)\n         {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/src/repacketizer_demo.c#L90-L126","documentation":"fopen(argv[argc-1], \"w\") on the output file returned NULL. The tool opens the output in write mode, which creates or truncates the file. A NULL return typically means the parent directory does not exist, the path points to a directory or special file, the filesystem is read-only, or the user lacks write permission. Notably, the tool correctly closes fin before exiting (line 109).","triggerScenarios":"Output directory does not exist; output path is a directory; read-only filesystem; disk quota exceeded; no write permission on the target directory.","commonSituations":"Forgetting to create the output directory; writing to /tmp on a system where it is mounted read-only; path typo; trying to overwrite a file owned by root without sudo.","solutions":["Create the output directory first: `mkdir -p $(dirname <output_path>)`.","Verify write permission on the target directory.","Ensure the output path is not an existing directory.","Check available disk space."],"exampleFix":"// before\nrepacketizer_demo in.oct /nonexistent_dir/out.oct\n// after\nmkdir -p /output/dir && repacketizer_demo in.oct /output/dir/out.oct","handlingStrategy":"validation","validationCode":"// Pre-check output directory writability\n#include <unistd.h>\n#include <libgen.h>\n#include <sys/stat.h>\nchar *path_copy = strdup(argv[argc-1]);\nchar *dir = dirname(path_copy);\nif (access(dir, W_OK) != 0) {\n    fprintf(stderr, \"Output directory not writable: %s\\n\", dir);\n    free(path_copy);\n    return EXIT_FAILURE;\n}\nfree(path_copy);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the output directory with `mkdir -p` before running.","Verify the output path does not point to an existing directory.","Check disk space with `df` for large batch operations."],"tags":["opus","cli","file-io","output-validation","repacketizer"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}