Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version;
        bh=IGJxEMEBXsbrNH1wMeqWAj7G8FmwMH2u+FAFC7Du7VU=;
        b=lUcxgY42c9xCoXshM4qCCqgwIMEbjQsNHMMZ0J1iytVnvbNYLZ86HLz9jBWQM6ADXt
         4yRbvzOyfsl7qy0reYAKh7fIDxCUEwMUjdNgvRrBuiwY5aAiUQdHTIcDhtU0fZc9C1z4
         ffiBLpKKopKWHQivDqZFrKFilYAedq+fVYdGp0Pp5xLh5zrsNH0VMxEj1jq9PGUpUyl/
         dQABZ6YBBD4rFnU352leeqAcfN78zppYIsAITDZjMoao4qZXAVMeEVO/zKN3PS1DRcrV
         xpblQVAfXG3i5HlNP8lADnDZsUq0douxduqQ/i3vc9Un+3dg0QKxHYo0vCHYtYshThHh
         cMDA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version;
        bh=IGJxEMEBXsbrNH1wMeqWAj7G8FmwMH2u+FAFC7Du7VU=;
        b=d5JM+QBbgSa+ESReqedJglSuO+b06vdNsqtHMOEnlIFI9UVkcA9KBaVIwfrlECG5JC
         9J+SYOsUy1w3lp8k/9ncrGiF4muhn8dgF5EhxJEXUVKolliQB7UQW3PT5g5EMA3kwFzR
         FMq6p29UcqOCbVCh2Gg0HucVLHSQKPMlGj1V4eJ0I88UjT+r9h1AWSFCt1YhX4m35W6M
         D0jLM0sfMpLvmtKJWWSYp6GvOPiKtHkAO8M9n5Kvzq3NFn1pwiBLc8ZHZA0lyZr5Jecx
         s5/lUq7rhagJszfviYL/8D4kTnnpb1I1Atbw5QQNjG62jV5Q8DEH+vIfoSOoe+9R7hAc
         8njw==
X-Gm-Message-State: AOPr4FUzxf25Vl85t5HrbE5zbmuSwvJm5a20g5F8bARVxSNcbJUlahUSTaa9WnArCRXuww==
X-Received: by 10.66.166.78 with SMTP id ze14mr38127171pab.149.1461449657776;
        Sat, 23 Apr 2016 15:14:17 -0700 (PDT)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160423151436.ZM6912@torch.brasslantern.com>
Date: Sat, 23 Apr 2016 15:14:36 -0700
In-Reply-To: <571BBF3C.50402@matrix.ai>
Comments: In reply to Roger Qiu <roger.qiu@matrix.ai>
        "Possible ZSH bug with IO direction" (Apr 24,  4:30am)
References: <571BBF3C.50402@matrix.ai>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: roger.qiu@matrix.ai, zsh-workers@zsh.org
Subject: Re: Possible ZSH bug with IO direction
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 38320

On Apr 24,  4:30am, Roger Qiu wrote:
}
}  > gm convert -compress JPEG - - < input.jpg > output.jpg
} gm convert: Corrupt JPEG data: 873 extraneous bytes before marker 0xd9 
} (/tmp/gmo1fx92).

I suspect you are encountering the issue that "gm" wants input.jpg in
binary mode, but zsh's input redirection operator has forced it to text
mode.  A lengthy comment in Src/main.c (copypasted below) explains this.  

There's [intended to be] an easy workaround, which is to open the file
for both read and write even though you're only going to read it:

    gm convert -compress JPEG - - <> input.jpg > output.jpg

However, it's been years since I had a Cygwin system or the time/patience
to care to set one up, so I haven't tested the workaround.

Aside:  The zsh/system module "sysopen" doesn't recognize O_BINARY or
O_TEXT modes; that should probably be corrected if someone can compile
on a system that has them, but of course the comment below indicates
that O_BINARY would be overridden anyway.


 * Peter A. Castro <doctor@fruitbat.org>
 *
 * Cygwin supports the notion of binary or text mode access to files
 * based on the mount attributes of the filesystem.  If a file is on
 * a binary mounted filesystem, you get exactly what's in the file, CRLF's
 * and all.  If it's on a text mounted filesystem, Cygwin will strip out
 * the CRs.  This presents a problem because zsh code doesn't allow for
 * CRLF's as line terminators.  So, we must force all open files to be
 * in text mode reguardless of the underlying filesystem attributes.
 * However, we only want to do this for reading, not writing as we still
 * want to write files in the mode of the filesystem.  To do this,
 * we have two options: augment all {f}open() calls to have O_TEXT added to
 * the list of file mode options, or have the Cygwin runtime do it for us.
 * I choose the latter. :)
 *
 * Cygwin's runtime provides pre-execution hooks which allow you to set
 * various attributes for the process which effect how the process functions.
 * One of these attributes controls how files are opened.  I've set
 * it up so that all files opened RDONLY will have the O_TEXT option set,
 * thus forcing line termination manipulation.  This seems to solve the
 * problem (at least the Test suite runs clean :).
 *
 * Note: this may not work in later implementations.  This will override
 * all mode options passed into open().  Cygwin (really Windows) doesn't
 * support all that much in options, so for now this is OK, but later on
 * it may not, in which case O_TEXT will have to be added to all opens calls
 * appropriately.

