The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/openzfs/module/lua/lcompat.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 2016 by Delphix. All rights reserved.
    3  */
    4 
    5 #include <sys/lua/lua.h>
    6 
    7 
    8 ssize_t
    9 lcompat_sprintf(char *buf, size_t size, const char *fmt, ...)
   10 {
   11         ssize_t res;
   12         va_list args;
   13 
   14         va_start(args, fmt);
   15         res = vsnprintf(buf, size, fmt, args);
   16         va_end(args);
   17 
   18         return (res);
   19 }
   20 
   21 int64_t
   22 lcompat_strtoll(const char *str, char **ptr)
   23 {
   24         int base;
   25         const char *cp;
   26         int digits;
   27         int64_t value;
   28         boolean_t is_negative;
   29 
   30         cp = str;
   31         while (*cp == ' ' || *cp == '\t' || *cp == '\n') {
   32                 cp++;
   33         }
   34         is_negative = (*cp == '-');
   35         if (is_negative) {
   36                 cp++;
   37         }
   38         base = 10;
   39 
   40         if (*cp == '') {
   41                 base = 8;
   42                 cp++;
   43                 if (*cp == 'x' || *cp == 'X') {
   44                         base = 16;
   45                         cp++;
   46                 }
   47         }
   48 
   49         value = 0;
   50         for (; *cp != '\0'; cp++) {
   51                 if (*cp >= '' && *cp <= '9') {
   52                         digits = *cp - '';
   53                 } else if (*cp >= 'a' && *cp <= 'f') {
   54                         digits = *cp - 'a' + 10;
   55                 } else if (*cp >= 'A' && *cp <= 'F') {
   56                         digits = *cp - 'A' + 10;
   57                 } else {
   58                         break;
   59                 }
   60                 if (digits >= base) {
   61                         break;
   62                 }
   63                 value = (value * base) + digits;
   64         }
   65 
   66         if (ptr != NULL) {
   67                 *ptr = (char *)cp;
   68         }
   69         if (is_negative) {
   70                 value = -value;
   71         }
   72         return (value);
   73 }
   74 
   75 int64_t
   76 lcompat_pow(int64_t x, int64_t y)
   77 {
   78         int64_t result = 1;
   79         if (y < 0)
   80                 return (0);
   81 
   82         while (y) {
   83                 if (y & 1)
   84                         result *= x;
   85                 y >>= 1;
   86                 x *= x;
   87         }
   88         return (result);
   89 }
   90 
   91 int
   92 lcompat_hashnum(int64_t x)
   93 {
   94         x = (~x) + (x << 18);
   95         x = x ^ (x >> 31);
   96         x = x * 21;
   97         x = x ^ (x >> 11);
   98         x = x + (x << 6);
   99         x = x ^ (x >> 22);
  100         return ((int)x);
  101 }

Cache object: 0a7cf5b926eded86cbed84220d4b121f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.