#!/bin/sh # print functions in C/C++ files that are not threadsafe # License: LGPLv2 # Example usage: # find -name "*.c" -o -name "*.cpp" | xargs threadsafe # If no files passed then the total list of functions # that are not threadsafe is printed. # # Obviously your man pages need to be accurate for this to work. # Redhat 9 has woefully incomplete man pages, # Fedora Core 3 (man-pages-1.67) has at least 12 # missing entries from apropos (gethostbyname_r for e.g.). # ubuntu 5.10 (manpages-2.02-2) does seem to be up to date though. # # TODO: remove false positives like .ctime ->rand ... apropos "_r" | sed -n 's#\(.*\)_r .*#\1#p' | uniq | #remove duplicates (from posix section for example) if test "$Argc" != "0" { env LANG=C grep -F -f- -w -n --color="auto" @Argv } else { cat } (CommandList children: [ (Pipeline children: [ (C {(apropos)} {(DQ (_r))}) (C {(sed)} {(-n)} {(SQ <"s#\\(.*\\)_r .*#\\1#p">)}) (C {(uniq)}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Pound "$#"))} {(KW_Bang "!") (Lit_Other "=")} {(DQ (0))} {(Lit_Other "]")} ) terminator: ) ] action: [ (SimpleCommand words: [ {(grep)} {(-F)} {(-f-)} {(-w)} {(-n)} {(--color) (Lit_Other "=") (DQ (auto))} {(DQ ($ VSub_At "$@"))} ] more_env: [(env_pair name:LANG val:{(C)} spids:[95])] ) ] spids: [-1 92] ) ] else_action: [(C {(cat)})] spids: [118 123] ) ] negated: False ) ] )