DrKLO/Telegram · error
%s: can't open %s\n
Error message
%s: can't open %s\n
What it means
After switch parsing, wrjpgcom opens the input JPEG. If a positional file name was supplied (argn < argc) but fopen(argv[argn], READ_BINARY) fails, it prints `%s: can't open %s` (progname, path) and exits EXIT_FAILURE. This is an input-image open failure, distinct from the -cfile open failure at line 437.
Source
Thrown at TMessagesProj/jni/mozjpeg/wrjpgcom.c:495
}
comment_length = (unsigned int)strlen(comment_arg);
} else
usage();
}
/* Cannot use both -comment and -cfile. */
if (comment_arg != NULL && comment_file != NULL)
usage();
/* If there is neither -comment nor -cfile, we will read the comment text
* from stdin; in this case there MUST be an input JPEG file name.
*/
if (comment_arg == NULL && comment_file == NULL && argn >= argc)
usage();
/* Open the input file. */
if (argn < argc) {
if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
exit(EXIT_FAILURE);
}
} else {
/* default input file is stdin */
#ifdef USE_SETMODE /* need to hack file mode? */
setmode(fileno(stdin), O_BINARY);
#endif
#ifdef USE_FDOPEN /* need to re-open in binary mode? */
if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open stdin\n", progname);
exit(EXIT_FAILURE);
}
#else
infile = stdin;
#endif
}
/* Open the output file. */View on GitHub (pinned to 45ab8f4308)
Solutions
- Confirm the input JPEG path exists and is readable (`test -r`).
- Quote paths containing spaces so they reach argv as one token.
- Use an absolute path to avoid cwd mismatch.
- Ensure the file is a valid readable JPEG, not a truncated/zero-byte file.
Example fix
// before wrjpgcom -cfile c.txt my photo.jpg // after wrjpgcom -cfile c.txt "my photo.jpg"
Defensive patterns
Strategy: validation
Validate before calling
#include <unistd.h>
/* verify input JPEG is readable before launching wrjpgcom */
if (access(input_jpg, R_OK) != 0) { /* report and abort */ } Prevention
- Quote input paths containing spaces.
- Use absolute input paths.
- Confirm the file is a complete, readable JPEG.
When it happens
Trigger: Running `wrjpgcom [opts] <input.jpg>` where <input.jpg> is missing, unreadable, not a regular file, or not a JPEG at all (open still succeeds for non-JPEG; this specific message is only the open failure).
Common situations: Wrong input path/extension typo, file deleted between parse and open, permission denied, or a path with spaces passed unquoted so argv splits incorrectly.
Related errors
- %s: can't open %s
- Comment text may not exceed %u bytes
- %s: must name one input and one output file\n
- %s: only one input file\n
- Comment text may not exceed %u bytes\n
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/ad9455ed2bf959a3.
Report an issue: GitHub.