Home > Enterprise >  `pclose` with NULL parameter
`pclose` with NULL parameter

Time:05-25

Which one should I choose:

1.pclose should not be attempted if popen has already failed, even though it's tolerant in handling NULL handle.

2.Passing whatever popen returns to pclose, just like it's ok to pass whatever malloc returns to free.

After I carefully read the manual(i.e.:man pclose), I can't find any evidence that pclose could handle NULL parameter.

CodePudding user response:

Since the documentation doesn't demand that pclose gracefully handle a NULL argument, you can't rely upon it. Now, it may be that a particular libc implementation provides that guarantee but, if you want to maintain portability, you should only rely upon guaranteed behavior.

  • Related