use macro to portably test for socket system call errors
use macro to portably test for socket system call errors

On some combinations of Montavista Linux running on Cavium Octeon
chips, some socket-related system calls erroneously return negative
numbers other than -1 to indicate errors, but inet_drv.c specifically
compares against -1 to test for errors. The result is that beam dumps
core due to the code treating these negative numbers as success
indicators, as counts/offsets of bytes written, etc. thereby
corrupting its own internal data structures.

To fix this, introduce a portability macro to test the result of
socket system calls. The test remains unchanged on Windows but for
other platforms the macro considers all return values that are less
than zero to be errors.

Though POSIX specifies that errors from these system calls are
indicated by a return value of -1, treating all negative return values
as errors is also safe, as described in detail below. In networking
programming, treating all negative return values from system calls as
errors is very common practice -- see the examples in W. Richard
Stevens's popular and highly lauded network programming books, for
example.

For system calls that return 0 to indicate success, treating all
negative numbers as errors is safe because only 0 is specified to
indicate success. These include:

getsockname
getpeername
getsockopt
gethostname
bind
listen
connect
close
shutdown

Likewise, for system calls that return non-negative numbers to
indicate success, treating all negative numbers as errors is also
safe. These functions typically return signed integers of type
ssize_t, and they treat any parameters of type size_t that cannot fit
within the ssize_t return value, such as numbers of bytes to read or
write, as errors (specifically EINVAL). For example, in the "ERRORS"
section of the man page for writev from several varieties of Linux, it
states that EINVAL is returned when the total length of the I/O is
more than can be expressed by the ssize_t return value.

These calls include:

recv
recvfrom
recvmsg
writev
send
sendto
sendmsg

Finaly, the socket() system call is also similar to these in that it
returns a signed type (int) with all non-negative return values
indicating success, so treating all negative return values as errors
is safe.

sdebnath/otp,hairyhum/otp,neeraj9/otp,bjorng/otp,bsmr-erlang/otp,lantti/otp,RJ/otp,psyeugenic/otp,emile/otp,saleyn/otp,potatosalad/otp,benoitc/otp-1,neeraj9/otp,mujiatong/otp,massemanet/otp,lightcyphers/otp,RichMorin/otp,lightcyphers/otp,bjorng/otp,theom/otp,potatosalad/otp,dumbbell/otp,schlagert/otp,basho/otp,paulcager/otp,hairyhum/otp,beni55/otp,sammoth-wazoku/otp,RaimoNiskanen/otp,riverrun/otp,paulcager/otp,johanclaesson/otp,kvakvs/otp,fenollp/otp,ader1990/otp,legoscia/otp,uabboli/otp,paulcager/otp,saleyn/otp,NOMORECOFFEE/otp,RJ/otp,RoadRunnr/otp,electricimp/otp,vladdu/otp,aboroska/otp,release-project/otp,rlipscombe/otp,ahmedshafeeq/otp,ahmedshafeeq/otp,klarna/otp,bsmr-erlang/otp,bjorng/otp,fenollp/otp,enikki/otp,msantos/otp,matwey/otp,enikki/otp,benoitc/otp-1,massemanet/otp,tuncer/otp,erlang/otp,getong/otp,msantos/otp,aboroska/otp,potatosalad/otp,lightcyphers/otp,Teino1978-Corp/otp,lucafavatella/otp,paladim/otp,neeraj9/otp,weisslj/otp,massemanet/otp,lianghaivv/otp,falkevik/otp,RichMorin/otp,lhslll/otp,weisslj/otp,bernardd/otp,dgud/otp,cobusc/otp,jinshana/otp,sdebnath/otp,theom/otp,sitexa/otp,msantos/otp,release-project/otp,bsmr-erlang/otp,electricimp/otp,massemanet/otp,isvilen/otp,bernardd/otp,g-andrade/otp,vladdu/otp,RoadRunnr/otp,lianghaivv/otp,schlagert/otp,g-andrade/otp,bernardd/otp,psyeugenic/otp,cnbin/otp,stolen/otp,emile/otp,mikpe/otp,kvakvs/otp,falkevik/otp,awetzel/otp,paladim/otp,vladdu/otp,jamesruan/otp,weisslj/otp,rlipscombe/otp,electricimp/otp,potatosalad/otp,falkevik/otp,NOMORECOFFEE/otp,mikpe/otp,hairyhum/otp,falkevik/otp,sammoth-wazoku/otp,RGafiyatullin/otp,platinumthinker/otp,schlagert/otp,cobusc/otp,tuncer/otp,RichMorin/otp,potatosalad/otp,krishnakumar4a4/otp,palas/otp,basho/otp,c-rack/otp,RaimoNiskanen/otp,enikki/otp,bernardd/otp,beni55/otp,jinshana/otp,klarna/otp,paulcager/otp,cnbin/otp,vladdu/otp,tuncer/otp,matwey/otp,fenollp/otp,legoscia/otp,lemenkov/otp,hairyhum/otp,benoitc/otp-1,matwey/otp,platinumthinker/otp,rlipscombe/otp,getong/otp,bsmr-erlang/otp,lhslll/otp,platinumthinker/otp,krishnakumar4a4/otp,haguenau/otp,theom/otp,sitexa/otp,rlipscombe/otp,uabboli/otp,riverrun/otp,kvakvs/otp,lrascao/otp,bsmr-erlang/otp,jemsbhai/otp,Teino1978-Corp/otp,erlang/otp,entropiae/otp,marquisthunder/otp,palas/otp,massemanet/otp,isvilen/otp,goertzenator/otp,fenollp/otp,jemsbhai/otp,getong/otp,paladim/otp,psyeugenic/otp,getong/otp,Teino1978-Corp/erlang-otp,klarna/otp,haguenau/otp,beni55/otp,lrascao/otp,emacsmirror/erlang,release-project/otp,goertzenator/otp,sitexa/otp,isvilen/otp,neeraj9/otp,derek121/otp,riverrun/otp,sammoth-wazoku/otp,legoscia/otp,lianghaivv/otp,isvilen/otp,dgud/otp,RoadRunnr/otp,palas/otp,isvilen/otp,lrascao/otp,stolen/otp,mikpe/otp,kvakvs/otp,ader1990/otp,riverrun/otp,NOMORECOFFEE/otp,lianghaivv/otp,emacsmirror/erlang,mikpe/otp,getong/otp,enikki/otp,lantti/otp,bernardd/otp,sdebnath/otp,marquisthunder/otp,vic/otp,bugs-erlang-org/otp,RoadRunnr/otp,ader1990/otp,rlipscombe/otp,emile/otp,enikki/otp,cnbin/otp,jinshana/otp,getong/otp,palas/otp,tuncer/otp,bernardd/otp,falkevik/otp,uabboli/otp,massemanet/otp,jamesruan/otp,RaimoNiskanen/otp,jj1bdx/otp,g-andrade/otp,lhslll/otp,lianghaivv/otp,paladim/otp,lucafavatella/otp,vladdu/otp,lrascao/otp,vinoski/otp,jinshana/otp,gjaldon/otp,msantos/otp,emacsmirror/erlang,saleyn/otp,saleyn/otp,emacsmirror/erlang,beni55/otp,NOMORECOFFEE/otp,RGafiyatullin/otp,sdebnath/otp,dgud/otp,lucafavatella/otp,mujiatong/otp,enikki/otp,schlagert/otp,dumbbell/otp,aboroska/otp,riverrun/otp,emacsmirror/erlang,matwey/otp,electricimp/otp,dgud/otp,release-project/otp,theom/otp,mikpe/otp,getong/otp,gjaldon/otp,marquisthunder/otp,RaimoNiskanen/otp,legoscia/otp,RGafiyatullin/otp,lucafavatella/otp,haguenau/otp,matwey/otp,enikki/otp,release-project/otp,vinoski/otp,johanclaesson/otp,cnbin/otp,mujiatong/otp,lhslll/otp,dumbbell/otp,jamesruan/otp,VincentHHL/otp,sdebnath/otp,bjorng/otp,psyeugenic/otp,gjaldon/otp,bugs-erlang-org/otp,jinshana/otp,ferd/otp,lantti/otp,rlipscombe/otp,bugs-erlang-org/otp,lemenkov/otp,ahmedshafeeq/otp,bsmr-erlang/otp,goertzenator/otp,jj1bdx/otp,mikpe/otp,jj1bdx/otp,falkevik/otp,lrascao/otp,paladim/otp,saleyn/otp,emacsmirror/erlang,krishnakumar4a4/otp,gjaldon/otp,electricimp/otp,jamesruan/otp,lianghaivv/otp,msantos/otp,weisslj/otp,vic/otp,lemenkov/otp,bernardd/otp,haguenau/otp,RGafiyatullin/otp,vic/otp,johanclaesson/otp,RichMorin/otp,RGafiyatullin/otp,dgud/otp,vladdu/otp,aboroska/otp,platinumthinker/otp,lantti/otp,erlang/otp,palas/otp,NOMORECOFFEE/otp,RJ/otp,cnbin/otp,rlipscombe/otp,derek121/otp,emile/otp,schlagert/otp,neeraj9/otp,entropiae/otp,entropiae/otp,stolen/otp,jj1bdx/otp,cobusc/otp,tuncer/otp,krishnakumar4a4/otp,cobusc/otp,massemanet/otp,emacsmirror/erlang,electricimp/otp,aboroska/otp,RoadRunnr/otp,paulcager/otp,NOMORECOFFEE/otp,matwey/otp,erlang/otp,massemanet/otp,g-andrade/otp,marquisthunder/otp,neeraj9/otp,dgud/otp,marquisthunder/otp,awetzel/otp,emacsmirror/erlang,sammoth-wazoku/otp,derek121/otp,g-andrade/otp,stolen/otp,potatosalad/otp,mikpe/otp,NOMORECOFFEE/otp,dgud/otp,palas/otp,bernardd/otp,jemsbhai/otp,rlipscombe/otp,Teino1978-Corp/erlang-otp,jinshana/otp,uabboli/otp,paulcager/otp,lucafavatella/otp,bsmr-erlang/otp,lianghaivv/otp,ader1990/otp,neeraj9/otp,vinoski/otp,ahmedshafeeq/otp,hairyhum/otp,matwey/otp,emile/otp,sdebnath/otp,g-andrade/otp,lantti/otp,vinoski/otp,goertzenator/otp,RJ/otp,schlagert/otp,legoscia/otp,aboroska/otp,vinoski/otp,gjaldon/otp,RGafiyatullin/otp,tuncer/otp,cobusc/otp,hairyhum/otp,GinjaNinja32/otp,haguenau/otp,bernardd/otp,lightcyphers/otp,uabboli/otp,uabboli/otp,sammoth-wazoku/otp,fenollp/otp,ahmedshafeeq/otp,lemenkov/otp,GinjaNinja32/otp,jemsbhai/otp,ferd/otp,mujiatong/otp,basho/otp,lightcyphers/otp,jemsbhai/otp,getong/otp,vladdu/otp,RoadRunnr/otp,gjaldon/otp,lemenkov/otp,lightcyphers/otp,jemsbhai/otp,basho/otp,jemsbhai/otp,vic/otp,stolen/otp,lightcyphers/otp,emile/otp,lhslll/otp,entropiae/otp,paladim/otp,ahmedshafeeq/otp,bjorng/otp,kvakvs/otp,beni55/otp,mujiatong/otp,erlang/otp,erlang/otp,isvilen/otp,cobusc/otp,vic/otp,psyeugenic/otp,rlipscombe/otp,dumbbell/otp,tuncer/otp,vinoski/otp,krishnakumar4a4/otp,RGafiyatullin/otp,basho/otp,psyeugenic/otp,GinjaNinja32/otp,GinjaNinja32/otp,isvilen/otp,haguenau/otp,yangchengjian/otp,dgud/otp,vinoski/otp,lantti/otp,mujiatong/otp,beni55/otp,goertzenator/otp,RichMorin/otp,getong/otp,Teino1978-Corp/erlang-otp,fenollp/otp,ferd/otp,VincentHHL/otp,emile/otp,vinoski/otp,cnbin/otp,jinshana/otp,RoadRunnr/otp,awetzel/otp,matwey/otp,lightcyphers/otp,potatosalad/otp,lucafavatella/otp,jj1bdx/otp,getong/otp,vinoski/otp,RJ/otp,cnbin/otp,Teino1978-Corp/erlang-otp,aboroska/otp,marquisthunder/otp,RaimoNiskanen/otp,entropiae/otp,c-rack/otp,basho/otp,c-rack/otp,sdebnath/otp,RJ/otp,benoitc/otp-1,RJ/otp,sitexa/otp,aboroska/otp,RaimoNiskanen/otp,kvakvs/otp,bjorng/otp,cobusc/otp,derek121/otp,jj1bdx/otp,cobusc/otp,yangchengjian/otp,vladdu/otp,Teino1978-Corp/otp,c-rack/otp,falkevik/otp,benoitc/otp-1,dumbbell/otp,lrascao/otp,ader1990/otp,c-rack/otp,VincentHHL/otp,VincentHHL/otp,goertzenator/otp,psyeugenic/otp,Teino1978-Corp/erlang-otp,lemenkov/otp,VincentHHL/otp,Teino1978-Corp/otp,g-andrade/otp,riverrun/otp,emacsmirror/erlang,GinjaNinja32/otp,yangchengjian/otp,jj1bdx/otp,kvakvs/otp,awetzel/otp,ader1990/otp,sammoth-wazoku/otp,release-project/otp,matwey/otp,bugs-erlang-org/otp,klarna/otp,marquisthunder/otp,VincentHHL/otp,bugs-erlang-org/otp,vic/otp,schlagert/otp,ferd/otp,basho/otp,erlang/otp,riverrun/otp,jamesruan/otp,theom/otp,dgud/otp,hairyhum/otp,potatosalad/otp,jj1bdx/otp,palas/otp,johanclaesson/otp,fenollp/otp,sammoth-wazoku/otp,VincentHHL/otp,electricimp/otp,bjorng/otp,krishnakumar4a4/otp,emacsmirror/erlang,vinoski/otp,saleyn/otp,yangchengjian/otp,GinjaNinja32/otp,vic/otp,erlang/otp,lantti/otp,c-rack/otp,sitexa/otp,electricimp/otp,stolen/otp,release-project/otp,tuncer/otp,uabboli/otp,uabboli/otp,RaimoNiskanen/otp,RaimoNiskanen/otp,potatosalad/otp,lhslll/otp,msantos/otp,gjaldon/otp,fenollp/otp,yangchengjian/otp,mikpe/otp,theom/otp,ahmedshafeeq/otp,dumbbell/otp,erlang/otp,msantos/otp,neeraj9/otp,hairyhum/otp,theom/otp,saleyn/otp,theom/otp,basho/otp,goertzenator/otp,ferd/otp,GinjaNinja32/otp,derek121/otp,sdebnath/otp,Teino1978-Corp/erlang-otp,klarna/otp,mujiatong/otp,beni55/otp,ahmedshafeeq/otp,weisslj/otp,electricimp/otp,jemsbhai/otp,entropiae/otp,massemanet/otp,legoscia/otp,RichMorin/otp,sammoth-wazoku/otp,krishnakumar4a4/otp,weisslj/otp,g-andrade/otp,ferd/otp,paladim/otp,rlipscombe/otp,lemenkov/otp,awetzel/otp,Teino1978-Corp/otp,ferd/otp,bugs-erlang-org/otp,awetzel/otp,enikki/otp,g-andrade/otp,jj1bdx/otp,ferd/otp,uabboli/otp,RoadRunnr/otp,gjaldon/otp,saleyn/otp,riverrun/otp,RoadRunnr/otp,goertzenator/otp,cnbin/otp,paulcager/otp,basho/otp,platinumthinker/otp,sitexa/otp,ahmedshafeeq/otp,release-project/otp,krishnakumar4a4/otp,derek121/otp,bsmr-erlang/otp,lantti/otp,dumbbell/otp,sitexa/otp,lrascao/otp,VincentHHL/otp,benoitc/otp-1,derek121/otp,c-rack/otp,yangchengjian/otp,bugs-erlang-org/otp,johanclaesson/otp,bjorng/otp,vic/otp,isvilen/otp,kvakvs/otp,legoscia/otp,dgud/otp,stolen/otp,weisslj/otp,mikpe/otp,mujiatong/otp,RaimoNiskanen/otp,bugs-erlang-org/otp,lhslll/otp,tuncer/otp,mikpe/otp,klarna/otp,isvilen/otp,lhslll/otp,palas/otp,lemenkov/otp,johanclaesson/otp,benoitc/otp-1,GinjaNinja32/otp,entropiae/otp,g-andrade/otp,bjorng/otp,Teino1978-Corp/erlang-otp,ader1990/otp,Teino1978-Corp/otp,bsmr-erlang/otp,release-project/otp,aboroska/otp,paulcager/otp,platinumthinker/otp,goertzenator/otp,msantos/otp,entropiae/otp,kvakvs/otp,legoscia/otp,isvilen/otp,RichMorin/otp,lrascao/otp,jamesruan/otp,jamesruan/otp,beni55/otp,schlagert/otp,haguenau/otp,lucafavatella/otp,yangchengjian/otp,bjorng/otp,lianghaivv/otp,RichMorin/otp,Teino1978-Corp/otp,lrascao/otp,klarna/otp,benoitc/otp-1,platinumthinker/otp,fenollp/otp,stolen/otp,jj1bdx/otp,dumbbell/otp,jinshana/otp,paladim/otp,jamesruan/otp,johanclaesson/otp,RJ/otp,weisslj/otp,sitexa/otp,RGafiyatullin/otp,weisslj/otp,derek121/otp,emile/otp,erlang/otp,awetzel/otp,falkevik/otp,emile/otp,NOMORECOFFEE/otp,Teino1978-Corp/erlang-otp,falkevik/otp,klarna/otp,Teino1978-Corp/otp,awetzel/otp,johanclaesson/otp,legoscia/otp,ferd/otp,psyeugenic/otp,yangchengjian/otp,saleyn/otp,dumbbell/otp,haguenau/otp,dumbbell/otp,potatosalad/otp,platinumthinker/otp,marquisthunder/otp,ader1990/otp,c-rack/otp,vladdu/otp,lucafavatella/otp