+bool check_id(const char *id) {
+ if(!id || !*id)
+ return false;
+
+ for(; *id; id++)
+ if(!isalnum(*id) && *id != '_')
+ return false;
+
+ return true;
+}
+
+bool check_netname(const char *netname, bool strict) {
+ if(!netname || !*netname || *netname == '.')
+ return false;
+
+ for(const char *c = netname; *c; c++) {
+ if(iscntrl(*c))
+ return false;
+ if(*c == '/' || *c == '\\')
+ return false;
+ if(strict && strchr(" $%<>:`\"|?*", *c))
+ return false;
+ }
+
+ return true;
+}
+
+/* Windows doesn't define HOST_NAME_MAX. */
+#ifndef HOST_NAME_MAX
+#define HOST_NAME_MAX 255
+#endif
+