{"record":{"id":"860d0aac9a307dff","repo":"DrKLO/Telegram","slug":"could-not-open-output-file-s-n","errorCode":null,"errorMessage":"Could not open output file %s\\n","messagePattern":"Could not open output file (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/celt/opus_custom_demo.c","lineNumber":99,"sourceCode":"   if (bytes_per_packet < 0 || bytes_per_packet > MAX_PACKET)\n   {\n      fprintf (stderr, \"bytes per packet must be between 0 and %d\\n\",\n                        MAX_PACKET);\n      return 1;\n   }\n\n   inFile = argv[argc-2];\n   fin = fopen(inFile, \"rb\");\n   if (!fin)\n   {\n      fprintf (stderr, \"Could not open input file %s\\n\", argv[argc-2]);\n      return 1;\n   }\n   outFile = argv[argc-1];\n   fout = fopen(outFile, \"wb+\");\n   if (!fout)\n   {\n      fprintf (stderr, \"Could not open output file %s\\n\", argv[argc-1]);\n      fclose(fin);\n      return 1;\n   }\n\n   enc = opus_custom_encoder_create(mode, channels, &err);\n   if (err != 0)\n   {\n      fprintf(stderr, \"Failed to create the encoder: %s\\n\", opus_strerror(err));\n      fclose(fin);\n      fclose(fout);\n      return 1;\n   }\n   dec = opus_custom_decoder_create(mode, channels, &err);\n   if (err != 0)\n   {\n      fprintf(stderr, \"Failed to create the decoder: %s\\n\", opus_strerror(err));\n      fclose(fin);\n      fclose(fout);","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/celt/opus_custom_demo.c#L81-L117","documentation":"fopen(outFile, \"wb+\") returned NULL — the output file cannot be created/opened for read-write. outFile is argv[argc-1], the last argument. The demo correctly closes the already-open input file before returning.","triggerScenarios":"The output path's directory does not exist, lacks write permission, the filesystem is read-only, or the path is invalid. \"wb+\" mode requires both write and read (read-back for the RESYNTH comparison).","commonSituations":"Output directory not created; no write permission to the target location; disk full; accidentally passing the same path as input (some systems allow it but semantics break); read-only mount.","solutions":["Ensure the output directory exists and is writable before running.","Use an absolute output path in a writable location (e.g. /tmp).","Free disk space if the volume is full.","Make sure input and output paths differ."],"exampleFix":"// before\n./test_opus_custom 48000 1 960 40 input.sw /nonexistent_dir/out.sw\n\n// after\nmkdir -p /tmp/out && ./test_opus_custom 48000 1 960 40 input.sw /tmp/out/out.sw","handlingStrategy":"validation","validationCode":"// Verify the output directory is writable before fopen(outFile,\"wb+\").\nchar dir[PATH_MAX]; parent_dir_of(outFile, dir, sizeof dir);\nif (access(dir, W_OK) != 0) { fclose(fin); fprintf(stderr, \"Output dir not writable: %s\\n\", dir); return 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the output directory exists and is writable (mkdir -p).","Make sure input and output paths are different.","Free disk space if the volume is full."],"tags":["io","file-write","permissions","opus","demo","cli","c"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}