{
    "mode": "man",
    "parameter": "perlclib",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/perlclib/1/json",
    "generated": "2026-05-30T05:15:11Z",
    "sections": {
        "NAME": {
            "content": "perlclib - Internal replacements for standard C library functions\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "One thing Perl porters should note is that perl doesn't tend to use that much of the C\nstandard library internally; you'll see very little use of, for example, the ctype.h\nfunctions in there. This is because Perl tends to reimplement or abstract standard library\nfunctions, so that we know exactly how they're going to operate.\n\nThis is a reference card for people who are familiar with the C library and who want to do\nthings the Perl way; to tell them which functions they ought to use instead of the more\nnormal C functions.\n",
            "subsections": [
                {
                    "name": "Conventions",
                    "content": "In the following tables:\n\n\"t\"\nis a type.\n\n\"p\"\nis a pointer.\n\n\"n\"\nis a number.\n\n\"s\"\nis a string.\n\n\"sv\", \"av\", \"hv\", etc. represent variables of their respective types.\n"
                },
                {
                    "name": "File Operations",
                    "content": "Instead of the stdio.h functions, you should use the Perl abstraction layer. Instead of\n\"FILE*\" types, you need to be handling \"PerlIO*\" types.  Don't forget that with the new\nPerlIO layered I/O abstraction \"FILE*\" types may not even be available. See also the\n\"perlapio\" documentation for more information about the following functions:\n\nInstead Of:                 Use:\n\nstdin                       PerlIOstdin()\nstdout                      PerlIOstdout()\nstderr                      PerlIOstderr()\n\nfopen(fn, mode)             PerlIOopen(fn, mode)\nfreopen(fn, mode, stream)   PerlIOreopen(fn, mode, perlio) (Dep-\nrecated)\nfflush(stream)              PerlIOflush(perlio)\nfclose(stream)              PerlIOclose(perlio)\n"
                },
                {
                    "name": "File Input and Output",
                    "content": "Instead Of:                 Use:\n\nfprintf(stream, fmt, ...)   PerlIOprintf(perlio, fmt, ...)\n\n[f]getc(stream)             PerlIOgetc(perlio)\n[f]putc(stream, n)          PerlIOputc(perlio, n)\nungetc(n, stream)           PerlIOungetc(perlio, n)\n\nNote that the PerlIO equivalents of \"fread\" and \"fwrite\" are slightly different from their C\nlibrary counterparts:\n\nfread(p, size, n, stream)   PerlIOread(perlio, buf, numbytes)\nfwrite(p, size, n, stream)  PerlIOwrite(perlio, buf, numbytes)\n\nfputs(s, stream)            PerlIOputs(perlio, s)\n\nThere is no equivalent to \"fgets\"; one should use \"svgets\" instead:\n\nfgets(s, n, stream)         svgets(sv, perlio, append)\n"
                },
                {
                    "name": "File Positioning",
                    "content": "Instead Of:                 Use:\n\nfeof(stream)                PerlIOeof(perlio)\nfseek(stream, n, whence)    PerlIOseek(perlio, n, whence)\nrewind(stream)              PerlIOrewind(perlio)\n\nfgetpos(stream, p)          PerlIOgetpos(perlio, sv)\nfsetpos(stream, p)          PerlIOsetpos(perlio, sv)\n\nferror(stream)              PerlIOerror(perlio)\nclearerr(stream)            PerlIOclearerr(perlio)\n"
                },
                {
                    "name": "Memory Management and String Handling",
                    "content": "Instead Of:                    Use:\n\nt* p = malloc(n)               Newx(p, n, t)\nt* p = calloc(n, s)            Newxz(p, n, t)\np = realloc(p, n)              Renew(p, n, t)\nmemcpy(dst, src, n)            Copy(src, dst, n, t)\nmemmove(dst, src, n)           Move(src, dst, n, t)\nmemcpy(dst, src, sizeof(t))    StructCopy(src, dst, t)\nmemset(dst, 0, n * sizeof(t))  Zero(dst, n, t)\nmemzero(dst, 0)                Zero(dst, n, char)\nfree(p)                        Safefree(p)\n\nstrdup(p)                      savepv(p)\nstrndup(p, n)                  savepvn(p, n) (Hey, strndup doesn't\nexist!)\n\nstrstr(big, little)            instr(big, little)\nstrcmp(s1, s2)                 strLE(s1, s2) / strEQ(s1, s2)\n/ strGT(s1,s2)\nstrncmp(s1, s2, n)             strnNE(s1, s2, n) / strnEQ(s1, s2, n)\n\nmemcmp(p1, p2, n)              memNE(p1, p2, n)\n!memcmp(p1, p2, n)             memEQ(p1, p2, n)\n\nNotice the different order of arguments to \"Copy\" and \"Move\" than used in \"memcpy\" and\n\"memmove\".\n\nMost of the time, though, you'll want to be dealing with SVs internally instead of raw \"char\n*\" strings:\n\nstrlen(s)                   svlen(sv)\nstrcpy(dt, src)             svsetpv(sv, s)\nstrncpy(dt, src, n)         svsetpvn(sv, s, n)\nstrcat(dt, src)             svcatpv(sv, s)\nstrncat(dt, src)            svcatpvn(sv, s)\nsprintf(s, fmt, ...)        svsetpvf(sv, fmt, ...)\n\nNote also the existence of \"svcatpvf\" and \"svvcatpvfn\", combining concatenation with\nformatting.\n\nSometimes instead of zeroing the allocated heap by using Newxz() you should consider\n\"poisoning\" the data.  This means writing a bit pattern into it that should be illegal as\npointers (and floating point numbers), and also hopefully surprising enough as integers, so\nthat any code attempting to use the data without forethought will break sooner rather than\nlater.  Poisoning can be done using the Poison() macros, which have similar arguments to\nZero():\n\nPoisonWith(dst, n, t, b)    scribble memory with byte b\nPoisonNew(dst, n, t)        equal to PoisonWith(dst, n, t, 0xAB)\nPoisonFree(dst, n, t)       equal to PoisonWith(dst, n, t, 0xEF)\nPoison(dst, n, t)           equal to PoisonFree(dst, n, t)\n"
                },
                {
                    "name": "Character Class Tests",
                    "content": "There are several types of character class tests that Perl implements.  The only ones\ndescribed here are those that directly correspond to C library functions that operate on\n8-bit characters, but there are equivalents that operate on wide characters, and UTF-8\nencoded strings.  All are more fully described in \"Character classification\" in perlapi and\n\"Character case changing\" in perlapi.\n\nThe C library routines listed in the table below return values based on the current locale.\nUse the entries in the final column for that functionality.  The other two columns always\nassume a POSIX (or C) locale.  The entries in the ASCII column are only meaningful for ASCII\ninputs, returning FALSE for anything else.  Use these only when you know that is what you\nwant.  The entries in the Latin1 column assume that the non-ASCII 8-bit characters are as\nUnicode defines, them, the same as ISO-8859-1, often called Latin 1.\n\nInstead Of:  Use for ASCII:   Use for Latin1:      Use for locale:\n\nisalnum(c)  isALPHANUMERIC(c) isALPHANUMERICL1(c) isALPHANUMERICLC(c)\nisalpha(c)  isALPHA(c)        isALPHAL1(c)        isALPHALC(u )\nisascii(c)  isASCII(c)                             isASCIILC(c)\nisblank(c)  isBLANK(c)        isBLANKL1(c)        isBLANKLC(c)\niscntrl(c)  isCNTRL(c)        isCNTRLL1(c)        isCNTRLLC(c)\nisdigit(c)  isDIGIT(c)        isDIGITL1(c)        isDIGITLC(c)\nisgraph(c)  isGRAPH(c)        isGRAPHL1(c)        isGRAPHLC(c)\nislower(c)  isLOWER(c)        isLOWERL1(c)        isLOWERLC(c)\nisprint(c)  isPRINT(c)        isPRINTL1(c)        isPRINTLC(c)\nispunct(c)  isPUNCT(c)        isPUNCTL1(c)        isPUNCTLC(c)\nisspace(c)  isSPACE(c)        isSPACEL1(c)        isSPACELC(c)\nisupper(c)  isUPPER(c)        isUPPERL1(c)        isUPPERLC(c)\nisxdigit(c) isXDIGIT(c)       isXDIGITL1(c)       isXDIGITLC(c)\n\ntolower(c)  toLOWER(c)        toLOWERL1(c)\ntoupper(c)  toUPPER(c)\n\nTo emphasize that you are operating only on ASCII characters, you can append \"A\" to each of\nthe macros in the ASCII column: \"isALPHAA\", \"isDIGITA\", and so on.\n\n(There is no entry in the Latin1 column for \"isascii\" even though there is an \"isASCIIL1\",\nwhich is identical to \"isASCII\";  the latter name is clearer.  There is no entry in the\nLatin1 column for \"toupper\" because the result can be non-Latin1.  You have to use\n\"toUPPERuvchr\", as described in \"Character case changing\" in perlapi.)\n\nstdlib.h functions\nInstead Of:                 Use:\n\natof(s)                     Atof(s)\natoi(s)                     grokatoUV(s, &uv, &e)\natol(s)                     grokatoUV(s, &uv, &e)\nstrtod(s, &p)               Strtod(s, &p)\nstrtol(s, &p, n)            Strtol(s, &p, b)\nstrtoul(s, &p, n)           Strtoul(s, &p, b)\n\nTypical use is to do range checks on \"uv\" before casting:\n\nint i; UV uv;\nchar* endptr = inputend;\nif (grokatoUV(input, &uv, &endptr)\n&& uv <= INTMAX)\ni = (int)uv;\n... /* continue parsing from endptr */\n} else {\n... /* parse error: not a decimal integer in range 0 .. MAXIV */\n}\n\nNotice also the \"grokbin\", \"grokhex\", and \"grokoct\" functions in numeric.c for converting\nstrings representing numbers in the respective bases into \"NV\"s.  Note that grokatoUV()\ndoesn't handle negative inputs, or leading whitespace (being purposefully strict).\n\nNote that strtol() and strtoul() may be disguised as Strtol(), Strtoul(), Atol(), Atoul().\nAvoid those, too.\n\nIn theory \"Strtol\" and \"Strtoul\" may not be defined if the machine perl is built on doesn't\nactually have strtol and strtoul. But as those 2 functions are part of the 1989 ANSI C spec\nwe suspect you'll find them everywhere by now.\n\nint rand()                  double Drand01()\nsrand(n)                    { seedDrand01((Randseedt)n);\nPLsrandcalled = TRUE; }\n\nexit(n)                     myexit(n)\nsystem(s)                   Don't. Look at ppsystem or use mypopen.\n\ngetenv(s)                   PerlEnvgetenv(s)\nsetenv(s, val)              mysetenv(s, val)\n"
                },
                {
                    "name": "Miscellaneous functions",
                    "content": "You should not even want to use setjmp.h functions, but if you think you do, use the \"JMPENV\"\nstack in scope.h instead.\n\nFor \"signal\"/\"sigaction\", use \"rsignal(signo, handler)\".\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "perlapi, perlapio, perlguts\n\n\n\nperl v5.34.0                                 2025-07-25                                  PERLCLIB(1)",
            "subsections": []
        }
    },
    "summary": "perlclib - Internal replacements for standard C library functions",
    "flags": [],
    "examples": [],
    "see_also": []
}