ka@hropus.UUCP (06/16/87)
"-" is certainly easier to type than "/dev/stdin" and is already somewhat
of a UN*X convention.
How do you implement it? Change the name of "open" to "_open" and
add the following subroutine to your library:
int open(file, mode, cmode)
char *file;
{
if (strcmp(file, "-") == 0 && (mode & 03) == 0)
return dup(0);
else
return _open(file, mode, cmode);
}
Of course this requires that your programs be recompiled if you don't
have shared libraries, but it's a lot cleaner than mucking around with
file descriptors from within a device driver. Even if you want a kernel
solution and prefer the name "/dev/stdin" I would still be inclined to
stick a check in nami rather than using a device driver, just as a matter
of style.
Kenneth Almquist
chris@mimsy.UUCP (06/16/87)
In article <1098@hropus.UUCP> ka@hropus.UUCP writes: >"-" is certainly easier to type than "/dev/stdin" and is already somewhat >of a UN*X convention. But only somewhat. The convention has always been a wart. One of the wonderful things about Unix is its simple naming scheme. Everything is a file. Want to see a file? `cat foo'. Want to see a directory? `cat .'. Want to see what is on a tape? `cat /dev/tape/rdefault' [*]. In V8 processes became files, through /proc. This is the right way to go. >... Even if you want a kernel solution and prefer the name "/dev/stdin" >I would still be inclined to stick a check in nami rather than using a >device driver, just as a matter of style. I guess style is in the eye of the beholder. Will you check for /dev/stdout and /dev/stderr too? But what about /dev/fd/17? ----- [*] Or /dev/rmt0 or /dev/rst0 or some other convention. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: seismo!mimsy!chris
ark@alice.UUCP (06/16/87)
In article <1098@hropus.UUCP>, ka@hropus.UUCP writes: > Of course this requires that your programs be recompiled if you don't > have shared libraries, but it's a lot cleaner than mucking around with > file descriptors from within a device driver. Even if you want a kernel > solution and prefer the name "/dev/stdin" I would still be inclined to > stick a check in nami rather than using a device driver, just as a matter > of style. It depends on what you want. If you want to turn "-" into a reserved name, fine. But while you're at it, why not build the names of all special files into the kernel? The reason, of course, is that the list of names is open-ended, so it would be necessary to change nami every time you wanted to add a new special file. I therefore think, just as a matter of style, that it's better to use the same mechanism for "/dev/stdin" that one uses for, say, "/dev/mem" -- a new major device number, a new entry in the switch table, and then use mknod to create special files with whatever name you like.
barnett@vdsvax.steinmetz.UUCP (Bruce G Barnett) (06/17/87)
In article <1098@hropus.UUCP> ka@hropus.UUCP writes: >"-" is certainly easier to type than "/dev/stdin" and is already somewhat >of a UN*X convention. Somewhat. `-' also means /dev/stdout. see tar(1) Of course we could break tar and tons of scripts :-) -- Bruce G. Barnett (barnett@ge-crd.ARPA) (barnett@steinmetz.UUCP) -- "The difference between a Buddha and an ordinary man is that one knows the difference and the other does not."
dave@murphy.UUCP (06/18/87)
In article <1098@hropus.UUCP>, ka@hropus.UUCP writes: > "-" is certainly easier to type than "/dev/stdin" and is already somewhat > of a UN*X convention. > > How do you implement it? Change the name of "open" to "_open" and > add the following subroutine to your library: [code deleted] Why not just make the shell recognize "-" by itself as a special argument and have it substitute "/dev/stdin"? The only problem that this would cause that I can think of is that you'd have to quote it to use it as the subtraction operator to expr, for instance. --- "Country beats the hell out of me" -- Jerry Dale McFadden Dave Cornutt, Gould Computer Systems, Ft. Lauderdale, FL [Ignore header, mail to these addresses] UUCP: ...!{sun,pur-ee,brl-bmd,seismo,bcopen,rb-dc1}!gould!dcornutt or ...!{ucf-cs,allegra,codas,hcx1}!novavax!gould!dcornutt ARPA: dcornutt@gswd-vms.arpa "The opinions expressed herein are not necessarily those of my employer, not necessarily mine, and probably not necessary."
ark@alice.UUCP (06/20/87)
In article <414@murphy.UUCP>, dave@murphy.UUCP writes: > Why not just make the shell recognize "-" by itself as a special argument and > have it substitute "/dev/stdin"? The only problem that this would cause that > I can think of is that you'd have to quote it to use it as the subtraction > operator to expr, for instance. echo This is a dubious suggestion - please rethink it.
allbery@ncoast.UUCP (06/20/87)
As quoted from <414@murphy.UUCP> by dave@murphy.UUCP (Snipe Hunter): +--------------- | In article <1098@hropus.UUCP>, ka@hropus.UUCP writes: | > "-" is certainly easier to type than "/dev/stdin" and is already somewhat | > of a UN*X convention. | [code deleted] | | Why not just make the shell recognize "-" by itself as a special argument and | have it substitute "/dev/stdin"? The only problem that this would cause that | I can think of is that you'd have to quote it to use it as the subtraction | operator to expr, for instance. +--------------- But what about "tar cvf - dir | compress > dir.tar.Z"? In this case you would want "-" to refer to /dev/stdout, no? And how is the shell to know THAT? (At least the mod to open() can check to see if the mode is O_RDONLY or O_WRONLY and use /dev/stdin or /dev/stdout based on the results -- not that I advocate that implementation.) ++Brandon -- Copyright (C) 1987 Brandon S. Allbery. Redistribution permitted only if the redistributor permits further redistribution. (Stargate take heed!) ---- Moderator for comp.sources.misc and comp.binaries.ibm.pc ---- Brandon S. Allbery {decvax,cbosgd}!cwruecmp!ncoast!allbery aXcess Company {ames,mit-eddie,talcott}!necntc!ncoast!allbery 6615 Center St. #A1-105 necntc!ncoast!allbery@harvard.HARVARD.EDU Mentor, OH 44060-4101 +01 216 974 9210 (also eddie.MIT.EDU)