Strcpy on SysV vs. BSD.
Howard Weiss
hsw at sparta.com
Fri Aug 31 22:46:36 AEST 1990
I've run into an interesting problem trying to use strcpy on a i386 machine
running Interactive 386/ix (SysV 3.2). At first I thought the library
routine for strcpy was blown away, but when I substituted my own string
copy routine and got the same results (a core dump), I knew somthing
strange was going on. Here is a short C program that demonstrates the problem:
main(){
char *TTx = "/dev/";
char tty[10]; /* works on both SysV and BSD */
/* char *tty; /* works only on BSD */
strcpy(tty,TTx);
printf("what's in tty now is %s\n",tty);
}
When I tried using the above program on SysV with the 'char *tty;'
declaration, it compiles fine, but core dumps when run. The same
thing occurs if I substitute 'while (*tty++ = *TTx++)' in place of the
library strcpy. Yet, the 'char *tty' compiles and runs fine on BSD!
To get this to work on SysV, I used the 'char tty[10]' declaration.
Any words of wisdom as to why this is the case would be appreciated!
I've worked on UNIX systems since V6 (in 1976) and I've never seen
this before.
Thanks,
Howard Weiss
Sparta,Inc.
Columbia, Md. 21046
hsw at sparta.com
More information about the Comp.unix.questions
mailing list