Well, since I made so many mistakes (possibly starting
with my posting of my porting notes :-)) and so many good
responses were given, I though I'd summarize what I've
learned:
(i). bcopy
I had been using
#define bcopy(src,dest,len) (memcpy(dest,src,len))
Now, it was pointed by many out that if src and
dest overlap, this is broken. One possibility is
#define bcopy(src,dest,len) (memmove(dest, src, len))
which according to the man page should handle
the overlaping case . Another possiblitity is
#define bcopy(src, dest, cnt) \
({ char *cccc; cccc= (char *) \
malloc(cnt); memcpy(cccc,src,cnt); \
memcpy(dest,cccc,cnt); free(cccc); })
This was from pacebes@tid.es (Pedro Acebes Bayon).
(ii). getcwd
I was missing an argument. Guy Harris and others
suggested
#define getwd(x) getcwd((x), <some number>)
"where <some number> might be MAXPATHLEN if you've
included a header file that defines it."
(iii). random
I had been using
#define random rand
As milun@cs.buffalo.edu (Davin Milun) points out,
"random() and rand() are no where near
equivalent."
He correctly proposes
#define random lrand48
(iv). Signals
Casper [casper@fwi.uva.nl (Casper H.S. Dik)] once
again was a great source here. As he points out
"sigblock (if not SVR4 segment) is equivalent to:
sigemptyset(&set);
sigaddset(&set, SIGWHAT);
sigaddset(&set, SIGOTHER);
.....
sigprocmask(SIG_BLOCK,&set, &oset);
/* do stuff between blocked signals */
sigprocmask(SIG_SETMASK,&oset, 0);
This is the easiers way to install sort of
BSD-ish compatible signal handlers. The main
difference between SunOS signal() and SVR4
sigset() is the restarting of system calls. In
SunOS (since 4.0 (or was it 4.1?)) system calls
are restarted. In SVR4 system calls are
interupted and return EINTR, unless the system
call is read, write and the like, in which case
the number of bytes read/written is returned when
that number exceeds 0. If no bytes have been
read/written, EINTR is returned. "
So, I guess we've agreed on the following (add Casper's
execellent comments):
#ifdef SOLARIS2
#include <stdlib.h>
#define srandom srand
#define random lrand48
#define bcopy(src,dest,len) (memmove(dest, src, len))
/* or possibly
#define bcopy(src, dest, cnt) ({ char *cccc; \
cccc= (char *) malloc(cnt); memcpy(cccc,src,cnt); \
memcpy(dest,cccc,cnt); free(cccc); })
*/
#define bzero(dest,len) (memset(dest, (char)NULL, len))
#define bcmp(b1,b2,n) (memcmp(b1,b2,n))
#define index(s,c) strchr(s,c)
#define rindex(s,c) strrchr(s,c)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define getwd(x) getcwd((x), <some number>)
/* where <some number> might be MAXPATHLEN if you've
included a header file that defines it. */
#endif /* SOLARIS2 */
#ifdef SOLARIS2
setvbuf(stderr, NULL, _IOLBF, 0);
#else
setlinebuf(stderr);
#endif /* SOLARIS2 */
#ifdef SOLARIS2
long gethostid() {
char buf[128];
if (sysinfo(SI_HW_SERIAL, buf, 128) == -1) {
perror("sysinfo");
exit(1);
}
return(strtol(buf,NULL,0));
}
#endif /* SOLARIS2 */
Finally, I find notes of this sort really useful. Maybe
someone should collect them all into a "Solaris 2.x
porting FAQ". I would be willing to compile such a FAQ if
people think it would be useful (and one doesn't already
exist, other than the Answerbook). Let me know.
At any rate, I really appreciate all the helpful
comments.
Thanks,
Dave
David M. Meyer Voice: 503/346-1747
Senior Network Engineer Pager: 503/342-9458
Office of University Computing FAX: 503/346-4397
Computing Center Internet: meyer@ns.uoregon.edu
University of Oregon
1225 Kincaid
Eugene, OR 97403
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:08:00 CDT