SCANC(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… SCANC β€” the kernel dev manual page, bestie edition ✨

okay so real talk: this is scanc from the Kernel Developer's Manual (section 9, obvi β€” kernel-land 🧚). it's a tiny little function with main character energy, and honestly? she ate. let's get into it πŸ’–


✨ NAME ✨

scanc β€” literally just uses a byte string as a lookup table index. that's the whole vibe. no cap πŸŽ€


🌸 SYNOPSIS 🌸

#include <lib/libkern/libkern.h>

int
scanc(u_int size, const u_char *cp, const u_char table[], int mask);

look at her. iconic signature. four args, one dream πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜•: scanc() scans the byte string cp, and the length of that string is size. simple enough, right?

then β€” and this is the fun part β€” a character in the string gets used as an index into the 256-byte table. like, every byte in your string is basically pointing at a lil spot in the table. iykyk 🫢

the scan stops when either of these happens:

  • a bitwise-AND of the byte from the table and mask isn't zero πŸ”₯
  • or the string is exhausted (you ran out of characters, bestie, it's over 😭)

that's it. that's the whole scan. no notes πŸ‘‘


⭐ RETURN VALUES ⭐

scanc() returns the length of the rest of the string β€” including the character that made the scan stop. yes, she's included, she's part of the count, don't do her dirty πŸ™ˆ

and if scanc() exhausted the string? it returns 0. zero. nada. the scan found nothing and honestly same πŸ’€


πŸŽ€ HISTORY πŸŽ€

scanc() emulates a VAX instruction with the same name. retro! vintage! a whole ancestor! we respect the lineage 🧚✨


πŸ’– friendly lil reminder: the details up there are load-bearing β€” the 256-byte table, the int-typed mask, the "including the stopping character" bit β€” so don't skip 'em, bestie 🫢

kisses, this was SCANC(9) from the Debian crew, dated April 24, 2013 β€” slay forever, periodt πŸ’…βœ¨

πŸ“¦ where this page comes from