Skip to content
Tcl Source Code Artifact [be0d00d527]
Login

Artifact [be0d00d527]

Artifact be0d00d527cdffbe26886bac2fa9f901c8588af8:

Ticket change [be0d00d527] - New ticket [1095909fffffffff|1095909fff] <i>Do not use readdir_r</i>. by jenglish on 2005-01-04 17:44:19.
D 2005-01-04T17:44:19
J assignee mdejong
J cmimetype text/plain
J comment If\sTcl\sis\scompiled\swith\s--enable-threads,\sit\suses\nreaddir_r()\s(or\sreaddir64_r)\sinstead\sof\sreaddir().\s\s\nThis\sis\sunnecessary:\saccording\sto\sthe\sSingle\sUnix\nSpecification,\s"The\spointer\sreturned\sby\sreaddir()\npoints\sto\sdata\swhich\smay\sbe\soverwritten\sby\sanother\scall\nto\sreaddir()\son\sthe\ssame\sdirectory\sstream.\sThis\sdata\sis\nnot\soverwritten\sby\sanother\scall\sto\sreaddir()\son\sa\ndifferent\sdirectory\sstream."\s\sIn\sother\swords:\sreaddir()\nis\sperfectly\sthread-safe\sas\slong\sas\syou\sdo\snot\sshare\nthe\ssame\sDIR\spointer\sacross\sdifferent\sthreads\s(which\nTcl\sdoes\snot\sdo).\n\nIn\saddition,\sTcl\sdoes\snot\sallocate\sthe\scorrect\samount\nof\sbuffer\sspace\s\sfor\sthe\spath\sname\s(in\sfact,\sthis\sis\nnot\seven\spossible\sin\sgeneral):\sthe\sofficially\nrecommended\smechanism\sis\sto\sset\sname_max\s=\npathconf(dirname,\s_PC_NAME_MAX),\sthen\sallocate\sa\sbuffer\nof\s'sizeof(struct\sdirent)\s+\sname_max\s+\s1'\sbytes,\ssince\nthe\smaximum\slength\sof\sa\sfilename\s(if\sthere\sis\sa\nmaximum)\sis\sfilesystem-specific.\n\nThis\sshould\sprevent\sbuffer\soverruns\s(assuming\nreaddir_r()\sis\simplemented\saccording\sto\sspec),\sbut\sit\ncan\sstill\struncate\sthe\sfilename\s--\son\sLinux,\sfor\nexample,\sit\sis\sdocumented\sthat\s"[f]iles\swith\sname\nlengths\slonger\sthan\s[...]\s_PC_NAME_MAX\smay\sexist\sin\sthe\ngiven\sdirectory".\n\nRelated\sissues:\s1071701,\s1001325,\s723502.\n\nAttached\spatch\s(to\sfollow)\sgets\srid\sof\sthe\swhole\smess\nand\sjust\suses\sreaddir().
J foundin obsolete:\s8.5a3
J priority 5\sMedium
J resolution None
J status Open
J submitter jenglish
J subsystem 52.\sPortability\sSupport
J title Do\snot\suse\sreaddir_r
J type Bug
K 1095909fffffffffffffffffffffffffffffffff
U jenglish
Z 1788b24cb7a2bdef54f7f391384ed190