linux-scalability-benchmarks / libowfat / scan / scan_ushort.c

The default branch has multiple heads

#include "scan.h"

/* this is cut and paste from scan_ulong instead of calling scan_ulong
 * because this way scan_ushort can abort scanning when the number would
 * not fit into an unsigned short (as opposed to not fitting in an
 * unsigned long) */

size_t scan_ushort(const char* src,unsigned short* dest) {
  if (sizeof(unsigned short) == sizeof(unsigned int)) {
    /* a good optimizing compiler should remove the else clause when not
     * needed */
    return scan_uint(src,(unsigned int*)dest);
  } else {
    register const char *tmp=src;
    register unsigned short int l=0;
    register unsigned char c;
    while ((c=*tmp-'0')<10) {
      unsigned short int n;
      /* division is very slow on most architectures */
      n=l<<3; if ((n>>3)!=l) break;
      if (n+(l<<1) < n) break;
      if (n+c < n) break;
    if (tmp-src) *dest=l;
    return tmp-src;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.