abc: syntax error in unix/u1file.c on System V
Jay Maynard
jmaynard at thesis1.hsch.utexas.edu
Sat Dec 22 09:04:53 AEST 1990
Problem: During compilation, file unix/u1file.c fails with a syntax error.
Environment: NCR Tower XP, System V release 2, OS release 3.02.01.
Description: The line in error is "extern char *getwd();". Under other than
AT&T System III/System V systems, this compiles as advertised. Under System
III/V, though, (any system that results in the ATT system type being selected
in Setup), this actually is compiled differently because of the line
"define getwd(path) getcwd(path, SIZE_BYTES)" in uhdrs/os.h - resulting in
the definition being turned into "extern char *getcwd(, SIZE_BYTES);". As
the compiler rightfully complains, this is a syntax error.
Fix: The following patch adds another definition to unix/os.h, for HAS_GETCWD;
adds logic in Setup to define it appropriately; changes unix/u1file.c to do
the right thing if it's set; and makes unix/u1os.c take it into account when
deciding whether or not to use its internal getwd() routine.
The patch may be applied by feeding this article to patch -p0.
---------------8<---------------cut here----------------->8-------------------
*** Setup.orig
--- Setup
**************
*** 686,691
perror="#define"
mkdir="#define"
getwd="#define"
rename="#define"
select="#define"
readdir="#define"
--- 686,692 -----
perror="#define"
mkdir="#define"
getwd="#define"
+ getcwd="#undef "
rename="#define"
select="#define"
readdir="#define"
**************
*** 695,700
perror="#define"
mkdir="#undef "
getwd="#undef "
rename="#undef "
select="#undef "
readdir="#undef "
--- 696,702 -----
perror="#define"
mkdir="#undef "
getwd="#undef "
+ getcwd="#undef "
rename="#undef "
select="#undef "
readdir="#undef "
**************
*** 704,709
perror="#define"
mkdir="#define"
getwd="#undef "
rename="#undef "
select="#undef "
readdir="#undef "
--- 706,712 -----
perror="#define"
mkdir="#define"
getwd="#undef "
+ getcwd="#define"
rename="#undef "
select="#undef "
readdir="#undef "
**************
*** 714,719
perror="#undef "
mkdir="#undef "
getwd="#undef "
rename="#undef "
select="#undef "
readdir="#undef "
--- 717,723 -----
perror="#undef "
mkdir="#undef "
getwd="#undef "
+ getcwd="#undef "
rename="#undef "
select="#undef "
readdir="#undef "
**************
*** 751,756
/^#define HAS_PERROR/s?#define?$perror?
/^#define HAS_MKDIR/s?#define?$mkdir?
/^#define HAS_GETWD/s?#define?$getwd?
/^#define HAS_RENAME/s?#define?$rename?
/^#define HAS_SELECT/s?#define?$select?
/^#define HAS_READDIR/s?#define?$readdir?
--- 755,761 -----
/^#define HAS_PERROR/s?#define?$perror?
/^#define HAS_MKDIR/s?#define?$mkdir?
/^#define HAS_GETWD/s?#define?$getwd?
+ /^#define HAS_GETCWD/s?#define?$getcwd?
/^#define HAS_RENAME/s?#define?$rename?
/^#define HAS_SELECT/s?#define?$select?
/^#define HAS_READDIR/s?#define?$readdir?
**************
*** 801,817
case $strchr in
strchr) $editor uhdrs/os.h <<EOF
/#define strchr/,/#define strrchr/d
- w
- q
- EOF
- ;;
- esac
-
- case $unix in
- ATT) $editor uhdrs/os.h <<EOF
- /#define HAS_GETWD/a
- #define getwd(path) getcwd(path, SIZE_PATH)
- .
w
q
EOF
--- 806,811 -----
case $strchr in
strchr) $editor uhdrs/os.h <<EOF
/#define strchr/,/#define strrchr/d
w
q
EOF
*** unix/u1file.c.orig
--- unix/u1file.c
**************
*** 6,11
#include "bfil.h"
extern char *getenv();
extern char *getwd();
Visible char *curdir() {
--- 6,14 -----
#include "bfil.h"
extern char *getenv();
+ #ifdef GETCWD
+ extern char *getcwd();
+ #else
extern char *getwd();
#endif
**************
*** 7,12
extern char *getenv();
extern char *getwd();
Visible char *curdir() {
static char buffer[SIZE_PATH];
--- 10,16 -----
extern char *getcwd();
#else
extern char *getwd();
+ #endif
Visible char *curdir() {
static char buffer[SIZE_PATH];
**************
*** 10,15
Visible char *curdir() {
static char buffer[SIZE_PATH];
return getwd(buffer);
}
--- 14,22 -----
Visible char *curdir() {
static char buffer[SIZE_PATH];
+ #ifdef GETCWD
+ return getcwd(buffer, SIZE_PATH);
+ #else
return getwd(buffer);
#endif
}
**************
*** 11,16
Visible char *curdir() {
static char buffer[SIZE_PATH];
return getwd(buffer);
}
Hidden string searchfile(base, abclib) string base; string abclib; {
--- 18,24 -----
return getcwd(buffer, SIZE_PATH);
#else
return getwd(buffer);
+ #endif
}
Hidden string searchfile(base, abclib) string base; string abclib; {
*** unix/u1os.c.orig
--- unix/u1os.c
**************
*** 16,21
#endif /* !NDEBUG */
#ifndef HAS_GETWD
/* getwd - get working directory */
--- 16,24 -----
#endif /* !NDEBUG */
+ #ifdef HAS_GETCWD
+ #define HAS_GETWD /* merge the two #defines */
+ #endif
#ifndef HAS_GETWD
/* getwd - get working directory */
*** uhdrs/os.h.gen.orig
--- uhdrs/os.h.gen
**************
*** 67,72
#define HAS_PERROR /* can use sys_errlist and sys_nerr (from perror(3)) */
#define HAS_MKDIR /* mkdir() and rmdir() available */
#define HAS_GETWD /* getwd() available */
#define HAS_RENAME /* rename() available */
#define HAS_SELECT /* 4.2 BSD select() system call available */
#define HAS_READDIR /* Berkeley style directory reading routines */
--- 67,73 -----
#define HAS_PERROR /* can use sys_errlist and sys_nerr (from perror(3)) */
#define HAS_MKDIR /* mkdir() and rmdir() available */
#define HAS_GETWD /* getwd() available */
+ #define HAS_GETCWD /* getcwd() available? */
#define HAS_RENAME /* rename() available */
#define HAS_SELECT /* 4.2 BSD select() system call available */
#define HAS_READDIR /* Berkeley style directory reading routines */
--
Jay Maynard, EMT-P, K5ZC, PP-ASEL | Never ascribe to malice that which can
jmaynard at thesis1.hsch.utexas.edu | adequately be explained by stupidity.
"...flames are a specific art form of Usenet..." -- Gregory C. Woodbury
More information about the Comp.sources.bugs
mailing list