DrKLO/Telegram · error

Could not open output file %s\n

Error message

Could not open output file %s\n

What it means

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.

Source

Thrown at TMessagesProj/jni/opus/celt/opus_custom_demo.c:99

   if (bytes_per_packet < 0 || bytes_per_packet > MAX_PACKET)
   {
      fprintf (stderr, "bytes per packet must be between 0 and %d\n",
                        MAX_PACKET);
      return 1;
   }

   inFile = argv[argc-2];
   fin = fopen(inFile, "rb");
   if (!fin)
   {
      fprintf (stderr, "Could not open input file %s\n", argv[argc-2]);
      return 1;
   }
   outFile = argv[argc-1];
   fout = fopen(outFile, "wb+");
   if (!fout)
   {
      fprintf (stderr, "Could not open output file %s\n", argv[argc-1]);
      fclose(fin);
      return 1;
   }

   enc = opus_custom_encoder_create(mode, channels, &err);
   if (err != 0)
   {
      fprintf(stderr, "Failed to create the encoder: %s\n", opus_strerror(err));
      fclose(fin);
      fclose(fout);
      return 1;
   }
   dec = opus_custom_decoder_create(mode, channels, &err);
   if (err != 0)
   {
      fprintf(stderr, "Failed to create the decoder: %s\n", opus_strerror(err));
      fclose(fin);
      fclose(fout);

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Ensure the output directory exists and is writable before running.
  2. Use an absolute output path in a writable location (e.g. /tmp).
  3. Free disk space if the volume is full.
  4. Make sure input and output paths differ.

Example fix

// before
./test_opus_custom 48000 1 960 40 input.sw /nonexistent_dir/out.sw

// after
mkdir -p /tmp/out && ./test_opus_custom 48000 1 960 40 input.sw /tmp/out/out.sw
Defensive patterns

Strategy: validation

Validate before calling

// Verify the output directory is writable before fopen(outFile,"wb+").
char dir[PATH_MAX]; parent_dir_of(outFile, dir, sizeof dir);
if (access(dir, W_OK) != 0) { fclose(fin); fprintf(stderr, "Output dir not writable: %s\n", dir); return 1; }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/860d0aac9a307dff. Report an issue: GitHub.