DrKLO/Telegram · error

%s: only one input file

Error message

%s: only one input file

What it means

When TWO_FILE_COMMANDLINE is NOT defined (Unix single-file style), cjpeg accepts at most one positional input (output goes to stdout). If file_index < argc-1 there is more than one positional file and this message prints, then usage() exits.

Source

Thrown at TMessagesProj/jni/mozjpeg/cjpeg.c:734

    if (outfilename == NULL) {
      if (file_index != argc - 2) {
        fprintf(stderr, "%s: must name one input and one output file\n",
                progname);
        usage();
      }
      outfilename = argv[file_index + 1];
    } else {
      if (file_index != argc - 1) {
        fprintf(stderr, "%s: must name one input and one output file\n",
                progname);
        usage();
      }
    }
  }
#else
  /* Unix style: expect zero or one file name */
  if (file_index < argc - 1) {
    fprintf(stderr, "%s: only one input file\n", progname);
    usage();
  }
#endif /* TWO_FILE_COMMANDLINE */

  /* Open the input file. */
  if (file_index < argc) {
    if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
      fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
      exit(EXIT_FAILURE);
    }
  } else {
    /* default input file is stdin */
    input_file = read_stdin();
  }

  /* Open the output file. */
  if (outfilename != NULL) {
    if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Pass at most one positional input file and redirect stdout for output, e.g. cjpeg in.ppm > out.jpg.
  2. If you need two-positional semantics, rebuild with TWO_FILE_COMMANDLINE defined or use -outfile.
  3. Collapse globs/loops to a single input per invocation.

Example fix

# before: two positionals on a Unix-style build
cjpeg in.ppm out.jpg
# after
cjpeg in.ppm > out.jpg
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/sh
# Unix-style build: at most one positional input
pos=()
for a in "$@"; do case "$a" in -*) ;; *) pos+=("$a");; esac; done
[ "${#pos[@]}" -gt 1 ] && { echo 'this cjpeg build accepts at most one input file; redirect stdout for output' >&2; exit 1; }
cjpeg "$@"

Type guard

// n/a: argv-count validation in the caller.

Try / catch

if ! cjpeg "$@" 2>/tmp/e; then
  grep -q 'only one input file' /tmp/e && { echo 'this build is Unix-style; use one input + stdout redirect'; exit 1; }
fi

Prevention

When it happens

Trigger: Running a non-TWO_FILE_COMMANDLINE build of cjpeg with two or more positional file arguments.

Common situations: Switching from a TWO_FILE_COMMANDLINE build (where two positionals are normal) to a Unix-style build and keeping the old invocation; shell glob producing multiple files; wrapper scripts that always append an output path.

Related errors


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