herror deprecated

萝らか妹 提交于 2019-12-12 14:31:32

问题


Answering another question, I stumbled upon the man page of a function called herror. It appears to be very much like perror except it prints errors related to some host lookup problem. The man page states that this function is “obsolete”. A function hsterror which could be used to turn the error number into a string without printing it is marked obsolete as well.

What I don't see is any indication as to why either of them is obsolete, and what replacement should be used instead. So what is the preferred way to turn an obscure h_errno error number into a user-readable string on a GNU libc linux system? Should every tiny application ship a translation table of its own, and hope that the set of possible error codes doesn't change any time soon?


回答1:


They are obsolete because gethostbyname* is obsolete. Use getaddrinfo instead, and use gai_strerror for errors.

From the gethostbyname(3) man page:

The gethostbyname*() and gethostbyaddr*() functions are obsolete. Applications should use getaddrinfo(3) and getnameinfo(3) instead.



来源:https://stackoverflow.com/questions/11832705/herror-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!