+/* $NetBSD: varpush.c,v 1.6 1997/10/12 00:54:44 lukem Exp $ */
+
/*
- * Copyright (c) 1982 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-/*static char sccsid[] = "from: @(#)varpush.c 5.6 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: varpush.c,v 1.2 1993/08/01 18:53:52 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)varpush.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: varpush.c,v 1.6 1997/10/12 00:54:44 lukem Exp $");
+#endif
#endif /* not lint */
# include <paths.h>
* @(#)varpush.c 1.1 (Berkeley) 4/1/82
*/
-int read(), write();
-
/*
* push variables around via the routine func() on the file
* channel file. func() is either read or write.
*/
+bool
varpush(file, func)
-reg int file;
-reg int (*func)(); {
-
- int temp;
+ int file;
+ ssize_t (*func) __P((int, const struct iovec *, int));
+{
+ int temp;
+ const struct iovec vec[] = {
+ { (void *) &Debug, sizeof Debug },
+ { (void *) &Finished, sizeof Finished },
+ { (void *) &Order, sizeof Order },
+ { (void *) &End, sizeof End },
+ { (void *) &On_exit, sizeof On_exit },
+ { (void *) &Handstart, sizeof Handstart },
+ { (void *) &Numgos, sizeof Numgos },
+ { (void *) Numseen, sizeof Numseen },
+ { (void *) &Play, sizeof Play },
+ { (void *) &Window, sizeof Window },
+ { (void *) Deck, sizeof Deck },
+ { (void *) &Discard, sizeof Discard },
+ { (void *) Player, sizeof Player }
+ };
- (*func)(file, (char *) &Debug, sizeof Debug);
- (*func)(file, (char *) &Finished, sizeof Finished);
- (*func)(file, (char *) &Order, sizeof Order);
- (*func)(file, (char *) &End, sizeof End);
- (*func)(file, (char *) &On_exit, sizeof On_exit);
- (*func)(file, (char *) &Handstart, sizeof Handstart);
- (*func)(file, (char *) &Numgos, sizeof Numgos);
- (*func)(file, (char *) Numseen, sizeof Numseen);
- (*func)(file, (char *) &Play, sizeof Play);
- (*func)(file, (char *) &Window, sizeof Window);
- (*func)(file, (char *) Deck, sizeof Deck);
- (*func)(file, (char *) &Discard, sizeof Discard);
- (*func)(file, (char *) Player, sizeof Player);
- if (func == read) {
- read(file, (char *) &temp, sizeof temp);
+ if (((func)(file, vec, sizeof(vec) / sizeof(vec[0]))) < 0) {
+ error(strerror(errno));
+ return FALSE;
+ }
+ if (func == readv) {
+ if ((read(file, (void *) &temp, sizeof temp)) < 0) {
+ error(strerror(errno));
+ return FALSE;
+ }
Topcard = &Deck[temp];
#ifdef DEBUG
if (Debug) {
printf("Debug file:");
gets(buf);
if ((outf = fopen(buf, "w")) == NULL) {
- perror(buf);
+ warn("%s", buf);
goto over;
}
if (strcmp(buf, _PATH_DEVNULL) != 0)
setbuf(outf, (char *)NULL);
}
#endif
- }
- else {
+ } else {
temp = Topcard - Deck;
- write(file, (char *) &temp, sizeof temp);
+ if ((write(file, (void *) &temp, sizeof temp)) < 0) {
+ error(strerror(errno));
+ return FALSE;
+ }
}
+ return TRUE;
}