shithub: gefs

Download patch

ref: 4848c1fc876c912f6cf148d732d2d02473aa242b
parent: e76fe27c3d86edf51dc6ccaade989fdd71ed44bf
author: Michael Forney <mforney@mforney.org>
date: Thu Feb 3 05:54:09 EST 2022

use char arrays for errors instead of string literals

The C standard leaves it unspecified whether different string
literals with identical contents have the same address or not.

kencc uses different addresses for each string literal, even if
they occur in the same translation unit, which breaks comparisons
like e != Eexist.

To fix this, use extern char arrays defined in error.c.

--- a/dat.h
+++ b/dat.h
@@ -97,77 +97,50 @@
 };
 
 /* internal errors */
-#define Eimpl	"not implemented"
 #define Efs	(abort(), "fs broke")
-#define Ebotch	"protocol botch"
-#define Eio	"i/o error"
-#define Efid	"unknown fid"
-#define Etype	"invalid fid type"
-#define Edscan	"invalid dir scan offset"
-#define Eexist	"directory entry not found"
-#define Emode	"unknown mode"
-#define Efull	"file system full"
-#define Eauth	"authentication failed"
-#define Elength	"name too long"
-#define Eperm	"permission denied"
-#define Einuse	"resource in use"
-#define Ebadf	"invalid file"
-#define Emem	"out of memory"
-#define Ename	"create/wstat -- bad character in file name"
-#define Enomem	"out of memory"
-#define Eattach	"attach required"
-#define Enosnap	"attach -- bad specifier"
-#define Edir	"invalid directory"
-#define Esyntax "syntax error"
-#define Enouser	"user does not exist"
-#define Efsize	"file too big"
-#define Ebadu	"attach -- unknown user or failed authentication"
-#define Erdonly	"file system read only"
-#define Elocked	"open/create -- file is locked"
-#define Eauthp	"authread -- auth protocol not finished"
-#define Eauthd	"authread -- not enough data"
-#define Ephase	"auth phase error"
-#define Enone	"auth -- user 'none' requires no authentication"
-#define Enoauth	"auth -- authentication disabled"
+extern char Eimpl[];
+extern char Ebotch[];
+extern char Eio[];
+extern char Efid[];
+extern char Etype[];
+extern char Edscan[];
+extern char Eexist[];
+extern char Emode[];
+extern char Efull[];
+extern char Eauth[];
+extern char Elength[];
+extern char Eperm[];
+extern char Einuse[];
+extern char Ebadf[];
+extern char Emem[];
+extern char Ename[];
+extern char Enomem[];
+extern char Eattach[];
+extern char Enosnap[];
+extern char Edir[];
+extern char Esyntax[];
+extern char Enouser[];
+extern char Efsize[];
+extern char Ebadu[];
+extern char Erdonly[];
+extern char Elocked[];
+extern char Eauthp[];
+extern char Eauthd[];
+extern char Ephase[];
+extern char Enone[];
+extern char Enoauth[];
 
-#define Ewstatb	"wstat -- unknown bits in qid.type/mode"
-#define Ewstatd	"wstat -- attempt to change directory"
-#define Ewstatg	"wstat -- not in group"
-#define Ewstatl	"wstat -- attempt to make length negative"
-#define Ewstatm	"wstat -- attempt to change muid"
-#define Ewstato	"wstat -- not owner or group leader"
-#define Ewstatp	"wstat -- attempt to change qid.path"
-#define Ewstatq	"wstat -- qid.type/dir.mode mismatch"
-#define Ewstatu	"wstat -- not owner"
-#define Ewstatv	"wstat -- attempt to change qid.vers"
-#define Enempty	"remove -- directory not empty"
-
-
-//#define Echar		"bad character in directory name"
-//#define Eopen		"read/write -- on non open fid"
-//#define Ecount	"read/write -- count too big"
-//#define Ealloc	"phase error -- directory entry not allocated"
-//#define Eqid		"phase error -- qid does not match"
-//#define Eaccess	"access permission denied"
-//#define Eentry	"directory entry not found"
-//#define Emode		"open/create -- unknown mode"
-//#define Edir1		"walk -- in a non-directory"
-//#define Edir2		"create -- in a non-directory"
-//#define Ephase	"phase error -- cannot happen"
-//#define Eexist	"create/wstat -- file exists"
-//#define Edot		"create/wstat -- . and .. illegal names"
-//#define Ewalk		"walk -- too many (system wide)"
-//#define Eoffset	"read/write -- offset negative"
-//#define Ebroken	"read/write -- lock is broken"
-//#define Eauth		"attach -- authentication failed"
-//#define Eauth2	"read/write -- authentication unimplemented"
-//#define Etoolong	"name too long"
-//#define Efidinuse	"fid in use"
-//#define Econvert	"protocol botch"
-//#define Eversion	"version conversion"
-//#define Eauthnone	"auth -- user 'none' requires no authentication"
-//#define Eauthdisabled	"auth -- authentication disabled",	/* development */
-//#define Eauthfile	"auth -- out of auth files"
+extern char Ewstatb[];
+extern char Ewstatd[];
+extern char Ewstatg[];
+extern char Ewstatl[];
+extern char Ewstatm[];
+extern char Ewstato[];
+extern char Ewstatp[];
+extern char Ewstatq[];
+extern char Ewstatu[];
+extern char Ewstatv[];
+extern char Enempty[];
 
 /*
  * All metadata blocks share a common header:
--- /dev/null
+++ b/error.c
@@ -1,0 +1,75 @@
+#include <u.h>
+#include <libc.h>
+#include <avl.h>
+#include <fcall.h>
+#include "dat.h"
+
+char Eimpl[]	= "not implemented";
+char Ebotch[]	= "protocol botch";
+char Eio[]	= "i/o error";
+char Efid[]	= "unknown fid";
+char Etype[]	= "invalid fid type";
+char Edscan[]	= "invalid dir scan offset";
+char Eexist[]	= "directory entry not found";
+char Emode[]	= "unknown mode";
+char Efull[]	= "file system full";
+char Eauth[]	= "authentication failed";
+char Elength[]	= "name too long";
+char Eperm[]	= "permission denied";
+char Einuse[]	= "resource in use";
+char Ebadf[]	= "invalid file";
+char Emem[]	= "out of memory";
+char Ename[]	= "create/wstat -- bad character in file name";
+char Enomem[]	= "out of memory";
+char Eattach[]	= "attach required";
+char Enosnap[]	= "attach -- bad specifier";
+char Edir[]	= "invalid directory";
+char Esyntax[]	= "syntax error";
+char Enouser[]	= "user does not exist";
+char Efsize[]	= "file too big";
+char Ebadu[]	= "attach -- unknown user or failed authentication";
+char Erdonly[]	= "file system read only";
+char Elocked[]	= "open/create -- file is locked";
+char Eauthp[]	= "authread -- auth protocol not finished";
+char Eauthd[]	= "authread -- not enough data";
+char Ephase[]	= "auth phase error";
+char Enone[]	= "auth -- user 'none' requires no authentication";
+char Enoauth[]	= "auth -- authentication disabled";
+
+char Ewstatb[]	= "wstat -- unknown bits in qid.type/mode";
+char Ewstatd[]	= "wstat -- attempt to change directory";
+char Ewstatg[]	= "wstat -- not in group";
+char Ewstatl[]	= "wstat -- attempt to make length negative";
+char Ewstatm[]	= "wstat -- attempt to change muid";
+char Ewstato[]	= "wstat -- not owner or group leader";
+char Ewstatp[]	= "wstat -- attempt to change qid.path";
+char Ewstatq[]	= "wstat -- qid.type/dir.mode mismatch";
+char Ewstatu[]	= "wstat -- not owner";
+char Ewstatv[]	= "wstat -- attempt to change qid.vers";
+char Enempty[]	= "directory is not empty";
+
+//char Echar[]		= "bad character in directory name";
+//char Eopen[]		= "read/write -- on non open fid";
+//char Ecount[]		= "read/write -- count too big";
+//char Ealloc[]		= "phase error -- directory entry not allocated";
+//char Eqid[]		= "phase error -- qid does not match";
+//char Eaccess[]	= "access permission denied";
+//char Eentry[]		= "directory entry not found";
+//char Emode[]		= "open/create -- unknown mode";
+//char Edir1[]		= "walk -- in a non-directory";
+//char Edir2[]		= "create -- in a non-directory";
+//char Ephase[]		= "phase error -- cannot happen";
+//char Eexist[]		= "create/wstat -- file exists";
+//char Edot[]		= "create/wstat -- . and .. illegal names";
+//char Ewalk[]		= "walk -- too many (system wide)";
+//char Eoffset[]	= "read/write -- offset negative";
+//char Ebroken[]	= "read/write -- lock is broken";
+//char Eauth[]		= "attach -- authentication failed";
+//char Eauth2[]		= "read/write -- authentication unimplemented";
+//char Etoolong[]	= "name too long";
+//char Efidinuse[]	= "fid in use";
+//char Econvert[]	= "protocol botch";
+//char Eversion[]	= "version conversion";
+//char Eauthnone[]	= "auth -- user 'none' requires no authentication";
+//char Eauthdisabled[]	= "auth -- authentication disabled";	/* development */
+//char Eauthfile[]	= "auth -- out of auth files";
--- a/mkfile
+++ b/mkfile
@@ -8,6 +8,7 @@
 	check.$O\
 	cons.$O\
 	dump.$O\
+	error.$O\
 	fs.$O\
 	hash.$O\
 	load.$O\