[comp.os.os2.programmer] C6.00 and errno

gerry@dialogic.UUCP (Gerry Lachac) (09/21/90)

I've started converting a large amount of MSC 5.1 code to 6.0, and ran
into a wall.  

My code sets errno to private values (returned by a custom driver).
In 5.1 this was no problem since errno was just an extern int.  In 6.0
(I assume to facilitate threads) errno is defined as a function.  I
cannot find anything in the documentation that lets me set the errno
value.  

The errno.h header file claims errno is set by "system functions".
Does anyone know how to set errno in C6.0?


-- 
uunet!dialogic!gerry   | "Even a dead plant turns  |	Dialogic Corporation
	OR	       |  over a new leaf 	   |	300 Littleton Rd
gerry@dialogic.UUCP    |  when the wind blows."	   |	Parsippany, NJ 07054 
		       |  			   |	(201)334-8450

gerry@dialogic.UUCP (Gerry Lachac) (09/21/90)

I've started converting a large amount of MSC 5.1 code to 6.0, and ran
into a wall.  

My code sets errno to private values (retubned by a custom driver).
In 5.1 this was no problem since errno was just an extern int.  In 6.0
(I assume to facilitate threads) errno is defined as a function.  I
cannot find anything in the documentation that lets me set the errno
value.  

The errno.h header file claims errno is set by "system functions".
Does anyone know how to set errno in C6.0?


-- 
uunet!dialogic!gerry   | "Even a dead plant turns  |	Dialogic Corporation
	OR	       |  over a new leaf 	   |	300 Littleton Rd
gerry@dialogic.UUCP    |  when the wind blows."	   |	Parsippany, NJ 07054 
		       |  			   |	(201)334-8450

jack@cscdec.cs.com (Jack Hudler) (09/22/90)

>
>The errno.h header file claims errno is set by "system functions".
>Does anyone know how to set errno in C6.0?
>
Yes, you are correct about the thread influence on errno.

Setting errno is pretty no-standard as your finding out, perhaps a 
better way might be to add your own error handling system. Such as;

..
n = read(fd,&i,2);
if (n<0)
  SetOurError(errno);	// to trap system errors
..
  SetOutError(some_error_number);	// and to generate your own.
..

or; (if your a fan of Global Variables)

..
n = read(fd,&i,2);
if (n<0)
  ErrorCode=errno;	// to trap system errors
..
  ErrorCode=some_error_number;	// and to generate your own.
..

-- 
Jack           Computer Support Corporation             Dallas,Texas
Hudler         Internet: jack@cscdec.cs.com

towfiq@interlan.Interlan.COM (Mark Towfiq) (09/25/90)

In article <1#19@dialogic.UUCP> gerry@dialogic.UUCP (Gerry Lachac) writes:

   My code sets errno to private values (retubned by a custom driver).
   In 5.1 this was no problem since errno was just an extern int.  In 6.0
   (I assume to facilitate threads) errno is defined as a function.  I
   cannot find anything in the documentation that lets me set the errno
   value.  

   The errno.h header file claims errno is set by "system functions".
   Does anyone know how to set errno in C6.0?

Several things to think of here -- 

	a) Are you sure you want to use errno?  Are you returning errors
	which make sense to the perror() routine, such as "File not found",
	"Permission denied", etc.?  If not, maybe you should use your own
	global variable.  This is especially necessary if you ever decide
	to write your own DLL, as it will no longer have access to the same
	errno as your application (I found this out the HARD way).

	b) If you still really want to use errno, just don't declare it
	yourself anywhere -- use stdlib.h, stddef.h and errno.h to set this
	def for you.  Then you can just use errno as before, like:

		if (errno == EINTR)
			errno = 0;

	Because errno is actually defined as a macro:

		#define errno *(_errno())

	And _errno() is a function which just returns the address of the
	errno variable.  Note that this is just true when you are using
	the DLL side of things, and it is in fact the only way to set global
	variables inside a DLL, as the only interface to a DLL is through
	its stub calls, which are just functions.

Hope this helps,
Mark
--
Mark Towfigh, Racal InterLan, Inc.                 towfiq@interlan.Interlan.COM
W: (508) 263-9929 H: (617) 488-2818                       uunet!interlan!towfiq

  "The Earth is but One Country, and Mankind its Citizens" -- Baha'u'llah