]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/BsdSocketLib/ns_ttl.c
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / StdLib / BsdSocketLib / ns_ttl.c
diff --git a/StdLib/BsdSocketLib/ns_ttl.c b/StdLib/BsdSocketLib/ns_ttl.c
deleted file mode 100644 (file)
index aba8479..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-/*\r
- * Copyright (c) 1996 by Internet Software Consortium.\r
- *\r
- * Permission to use, copy, modify, and distribute this software for any\r
- * purpose with or without fee is hereby granted, provided that the above\r
- * copyright notice and this permission notice appear in all copies.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\r
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\r
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
- * SOFTWARE.\r
- */\r
-\r
-/*\r
- * Portions copyright (c) 1999, 2000\r
- * Intel Corporation.\r
- * All rights reserved.\r
- * \r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * \r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer.\r
- * \r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the\r
- *    documentation and/or other materials provided with the distribution.\r
- * \r
- * 3. All advertising materials mentioning features or use of this software\r
- *    must display the following acknowledgement:\r
- * \r
- *    This product includes software developed by Intel Corporation and\r
- *    its contributors.\r
- * \r
- * 4. Neither the name of Intel Corporation or its contributors may be\r
- *    used to endorse or promote products derived from this software\r
- *    without specific prior written permission.\r
- * \r
- * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''\r
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- * ARE DISCLAIMED.  IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE\r
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\r
- * THE POSSIBILITY OF SUCH DAMAGE.\r
- * \r
- */\r
-\r
-/* Import. */\r
-\r
-#include <arpa/nameser.h>\r
-\r
-#include <ctype.h>\r
-#include <errno.h>\r
-#include <stdio.h>\r
-#include <string.h>\r
-\r
-#define SPRINTF(x) ((size_t)sprintf x)\r
-\r
-/* Forward. */\r
-\r
-static int     fmt1(int t, char s, char **buf, size_t *buflen);\r
-\r
-/* Macros. */\r
-\r
-#define T(x) if ((x) < 0) return (-1); else (void)NULL\r
-\r
-/* Public. */\r
-\r
-int\r
-ns_format_ttl(u_long src, char *dst, size_t dstlen) {\r
-       char *odst = dst;\r
-       int secs, mins, hours, days, weeks, x;\r
-       char *p;\r
-\r
-       secs =  (int)(src % 60);  src /= 60;\r
-       mins =  (int)(src % 60);  src /= 60;\r
-       hours = (int)(src % 24);  src /= 24;\r
-       days =  (int)(src % 7);   src /= 7;\r
-       weeks = (int)src;         src = 0;\r
-\r
-       x = 0;\r
-       if (weeks) {\r
-               T(fmt1(weeks, 'W', &dst, &dstlen));\r
-               x++;\r
-       }\r
-       if (days) {\r
-               T(fmt1(days, 'D', &dst, &dstlen));\r
-               x++;\r
-       }\r
-       if (hours) {\r
-               T(fmt1(hours, 'H', &dst, &dstlen));\r
-               x++;\r
-       }\r
-       if (mins) {\r
-               T(fmt1(mins, 'M', &dst, &dstlen));\r
-               x++;\r
-       }\r
-       if (secs || !(weeks || days || hours || mins)) {\r
-               T(fmt1(secs, 'S', &dst, &dstlen));\r
-               x++;\r
-       }\r
-\r
-       if (x > 1) {\r
-               int ch;\r
-\r
-               for (p = odst; (ch = *p) != '\0'; p++)\r
-                       if (isascii(ch) && isupper(ch))\r
-                               *p = (char)( tolower(ch));\r
-       }\r
-\r
-       return ((int)(dst - odst));\r
-}\r
-\r
-int\r
-ns_parse_ttl(const char *src, u_long *dst) {\r
-       u_long ttl, tmp;\r
-       int ch, digits, dirty;\r
-\r
-       ttl = 0;\r
-       tmp = 0;\r
-       digits = 0;\r
-       dirty = 0;\r
-       while ((ch = *src++) != '\0') {\r
-               if (!isascii(ch) || !isprint(ch))\r
-                       goto einval;\r
-               if (isdigit(ch)) {\r
-                       tmp *= 10;\r
-                       tmp += (ch - '0');\r
-                       digits++;\r
-                       continue;\r
-               }\r
-               if (digits == 0)\r
-                       goto einval;\r
-               if (islower(ch))\r
-                       ch = toupper(ch);\r
-               switch (ch) {\r
-               case 'W':  tmp *= 7;\r
-               case 'D':  tmp *= 24;\r
-               case 'H':  tmp *= 60;\r
-               case 'M':  tmp *= 60;\r
-               case 'S':  break;\r
-               default:   goto einval;\r
-               }\r
-               ttl += tmp;\r
-               tmp = 0;\r
-               digits = 0;\r
-               dirty = 1;\r
-       }\r
-       if (digits > 0) {\r
-               if (dirty)\r
-                       goto einval;\r
-               else\r
-                       ttl += tmp;\r
-       }\r
-       *dst = ttl;\r
-       return (0);\r
-\r
- einval:\r
-       errno = EINVAL;\r
-       return (-1);\r
-}\r
-\r
-/* Private. */\r
-\r
-static int\r
-fmt1(int t, char s, char **buf, size_t *buflen) {\r
-       char tmp[50];\r
-       size_t len;\r
-\r
-       len = SPRINTF((tmp, "%d%c", t, s));\r
-       if (len + 1 > *buflen)\r
-               return (-1);\r
-       strcpy(*buf, tmp);\r
-       *buf += len;\r
-       *buflen -= len;\r
-       return (0);\r
-}\r