DrKLO/Telegram · error
Error opening output file: %s\n
Error message
Error opening output file: %s\n
What it means
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).
Source
Thrown at TMessagesProj/jni/opus/src/repacketizer_demo.c:108
} else if (strcmp(argv[i], "-split")==0)
split = 1;
else
{
fprintf(stderr, "Unknown option: %s\n", argv[i]);
usage(argv[0]);
return EXIT_FAILURE;
}
}
fin = fopen(argv[argc-2], "r");
if(fin==NULL)
{
fprintf(stderr, "Error opening input file: %s\n", argv[argc-2]);
return EXIT_FAILURE;
}
fout = fopen(argv[argc-1], "w");
if(fout==NULL)
{
fprintf(stderr, "Error opening output file: %s\n", argv[argc-1]);
fclose(fin);
return EXIT_FAILURE;
}
rp = opus_repacketizer_create();
while (!eof)
{
int err;
int nb_packets=merge;
opus_repacketizer_init(rp);
for (i=0;i<nb_packets;i++)
{
unsigned char ch[4];
err = fread(ch, 1, 4, fin);
len[i] = char_to_int(ch);
/*fprintf(stderr, "in len = %d\n", len[i]);*/
if (len[i]>1500 || len[i]<0)
{View on GitHub (pinned to 45ab8f4308)
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.
Example fix
// before repacketizer_demo in.oct /nonexistent_dir/out.oct // after mkdir -p /output/dir && repacketizer_demo in.oct /output/dir/out.oct
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check output directory writability
#include <unistd.h>
#include <libgen.h>
#include <sys/stat.h>
char *path_copy = strdup(argv[argc-1]);
char *dir = dirname(path_copy);
if (access(dir, W_OK) != 0) {
fprintf(stderr, "Output directory not writable: %s\n", dir);
free(path_copy);
return EXIT_FAILURE;
}
free(path_copy); Prevention
- 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.
When it happens
Trigger: Output directory does not exist; output path is a directory; read-only filesystem; disk quota exceeded; no write permission on the target directory.
Common situations: 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.
Related errors
- Error opening input file: %s\n
- Error writing.\n
- usage: %s [options] input_file output_file\n
- -merge parameter must be at least 1.\n
- -merge parameter must be less than 48.\n
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/31d93730f62750a5.
Report an issue: GitHub.