DrKLO/Telegram · error

%s: must name one input and one output file\n

Error message

%s: must name one input and one output file\n

What it means

Under the TWO_FILE_COMMANDLINE build variant, wrjpgcom requires exactly one input and one output file name. After consuming switches, if argn != argc - 2 (i.e. not exactly two positional args remain), it prints `%s: must name one input and one output file`, calls usage(), and exits. This is a positional-argument-count mismatch.

Source

Thrown at TMessagesProj/jni/mozjpeg/wrjpgcom.c:517

    /* 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. */
#ifdef TWO_FILE_COMMANDLINE
  /* Must have explicit output file name */
  if (argn != argc - 2) {
    fprintf(stderr, "%s: must name one input and one output file\n", progname);
    usage();
  }
  if ((outfile = fopen(argv[argn + 1], WRITE_BINARY)) == NULL) {
    fprintf(stderr, "%s: can't open %s\n", progname, argv[argn + 1]);
    exit(EXIT_FAILURE);
  }
#else
  /* Unix style: expect zero or one file name */
  if (argn < argc - 1) {
    fprintf(stderr, "%s: only one input file\n", progname);
    usage();
  }
  /* default output file is stdout */
#ifdef USE_SETMODE              /* need to hack file mode? */
  setmode(fileno(stdout), O_BINARY);
#endif
#ifdef USE_FDOPEN               /* need to re-open in binary mode? */
  if ((outfile = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Supply exactly two positional paths: input JPEG then output JPEG.
  2. Rebuild mozjpeg without TWO_FILE_COMMANDLINE if stdout-based piping is required.
  3. Check the build's commandline convention (Unix vs two-file) before scripting invocations.

Example fix

// before
wrjpgcom -comment hi in.jpg
// after
wrjpgcom -comment hi in.jpg out.jpg
Defensive patterns

Strategy: validation

Validate before calling

/* for a TWO_FILE_COMMANDLINE build, require exactly 2 positional args */
int positional = argc_after_switches;
if (positional != 2) { /* print expected usage: input AND output */ }

Prevention

When it happens

Trigger: Running a TWO_FILE_COMMANDLINE build of wrjpgcom with zero, one, or three+ positional file arguments instead of exactly two (input + output).

Common situations: Porting a Unix-style invocation (single file, output to stdout) to a Windows/TWO_FILE_COMMANDLINE build, or forgetting the output file argument.

Related errors


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