USGCORB%LEHIIBM1.BITNET@wiscvm.wisc.edu (Stephen Corbesero) (08/06/87)
I have been porting software mostly to System V Unix for some time now, and the following problems seem to pop up constantly. 1. How does SysV do a rename? I.e, what is the equivalent of the Berkeley rename system call? 2. Has anyone written a ftruncate (again a Berkeley-ism) for SysV? 3. How does one patch an arbitrary binary file? I need something like Norton's IBM PC utilities. Stephen Corbesero CSEE Dept, Lehigh University
guy%gorodish@Sun.COM (Guy Harris) (08/07/87)
I tried mailing this, but got: ----- Transcript of session follows ----- Connected to wiscvm.wisc.edu: >>> RCPT To:<USGCORB@LEHIIBM1.bitnet> <<< 550 Host 'LEHIIBM1.bitnet' Unknown 550 <USGCORB@LEHIIBM1.BITNET>... User unknown So: > 1. How does SysV do a rename? I.e, what is the equivalent of the > Berkeley rename system call? Well, you can rename non-directory files with: #include <errno.h> extern int errno; int rename(from, to) char *from; char *to; { if (unlink(to) < 0 && errno != ENOENT) return (-1); if (link(from, to) < 0) return (-1); return (unlink(from)); } (which will, of course, work on 4.[23]BSD also, but "rename" is preferable because it tries to eliminate the small windows in which there is either no file named by the path pointed to by "to" or where both the links "from" and "to" exist). If "to" or "from" are directories, this will "work" only if you're the super-user, and it won't work correctly; you'd have do make sure the directory referred to by "to" is empty, and then properly change the ".." link for the directory being renamed, if necessary. > 2. Has anyone written a ftruncate (again a Berkeley-ism) for SysV? Unfortunately, you can't. The only way to truncate a file in systems lacking something like "ftruncate" is to do a "creat" or an "open" with the O_TRUNC flag; to do this, you need the pathname of the file. Furthermore, this only truncates the file to zero length; the only way to shorten a file to a non-zero length is to copy the part to be retained to a temporary file and then copy it back to the original file. Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com
herman%nrl.decnet@ccf3.nrl.navy.mil (NRL::HERMAN) (01/02/90)
I have two questions about using Version V (3.2) Unix. i) How can I get the prompt to show me the current directory. ii) Is there something available in System V which is equivalent to the 'alias' command available in BSD UNIX. That is, can one define symbols in a way similar to the way #define defines symbols in C. Charles Herman herman@cmvax.nrl.navy.mil
hpn@att.att.com (01/02/90)
About getting the prompt to show your current working directory, try this: PS1='${PWD##}' About the alias, try this: alias dir=ls -l To get a list of already defined aliases, just type 'alias'. Or try 'man alias' Huy Nguyen
davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) (01/02/90)
In article <21916@adm.BRL.MIL> herman%nrl.decnet@ccf3.nrl.navy.mil (NRL::HERMAN) writes: Answers here apply to Korn shell (ksh) only. | i) How can I get the prompt to show me the current directory. PS1='$PWD> ' ^^^^ Working directory (must be in ', not ") | | ii) Is there something available in System V which is equivalent to the | 'alias' command available in BSD UNIX. That is, can one define | symbols in a way similar to the way #define defines symbols in C. ksh has alias, as well as shell functions -- bill davidsen (davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen) "The world is filled with fools. They blindly follow their so-called 'reason' in the face of the church and common sense. Any fool can see that the world is flat!" - anon
chet@cwns1.CWRU.EDU (Chet Ramey) (01/03/90)
In article <21917@adm.BRL.MIL> mwood!attcc!hpn@att.att.com writes: >About getting the prompt to show your current working directory, try this: > >PS1='${PWD##}' Try getting the Korn Shell or bash (the Gnu Bourne-Again SHell) before expecting this to work. >About the alias, try this: >alias dir=ls -l Again, get bash first. They try alias dir="ls -l" The quotes are required for any alias containing white space. This is what bash does with the unquoted form: cwns1$ alias dir=ls -l alias: -l not found >Or try 'man alias' Misleading. On my systems, `man alias' is equivalent to `man csh'. Chet Ramey -- Chet Ramey Network Services Group "Help! Help! I'm being Case Western Reserve University repressed!" chet@ins.CWRU.Edu
cc@wet.UUCP (Christopher Cilley) (01/03/90)
In article <21916@adm.BRL.MIL> herman%nrl.decnet@ccf3.nrl.navy.mil (NRL::HERMAN) asks: > > i) How can I get the prompt to show me the current directory. > > ii) Is there something available in System V which is equivalent to the > 'alias' command available in BSD UNIX. That is, can one define > symbols in a way similar to the way #define defines symbols in C. I can pass along the answers for C-shell (/bin/csh). i) I have the following in my .cshrc in the home directory: # The following sets your prompt to print out the current command number # and working directory. alias cd ' cd \!* ; set prompt = "`pwd` [\\!] " ' This will give output that looks like: /usr/local/lib/elm [23] <Your command here...> ii) You can set aliases by just putting them in the .cshrc like this: # Set local aliases. alias h cd $home alias hi history alias chterm 'set TERM=\!* ; setenv TERM \!* ; tput init' alias ll ls -al alias llm 'ls -al \!* | less' alias lc ls -aCF alias psa ps -ef alias mail mailx alias bye logout etc. etc. -- ---------- ---------- ---------- ---------- ---------- Christopher Cilley {ucsfcca|claris}!wet!cc cc@wet.UUCP "Life is uncertain - eat dessert first..." -RJR
guy@auspex.auspex.com (Guy Harris) (01/03/90)
>About getting the prompt to show your current working directory, try this: > >PS1='${PWD##}' > >About the alias, try this: > >alias dir=ls -l Sounds like you're using the Korn shell which is not a standard part of System V Releases 3.0 or 3.1; it's standard in 4.0 (along with the C shell, based on the SunOS 4.1 one which is based on the 4.3BSD one and which therefore supports "alias" just like the original poster's BSD system), and maybe in some other versions. If all you have is the Bourne shell, there may be other ways to get the current working directory (I've seen some, I think, but they're a bit complicated), and you can get things like the "dir" alias with shell functions. You can't use the above methods, though, not in a vanilla Bourne shell. However, some S5 systems do come with the C shell (S5R4, as indicated, and apparently S5R3.2, at least for the 386).