[comp.lang.c] String Handling -- strcpy

msb@sq.UUCP (04/20/87)

Mike Stump (aeusemrs@csun.UUCP) writes:

> Well, not to pick on you, but, have you ever done ANY programming using shared
> memory, succesfully, and bug free?

Just enough to be aware of the problems involved.

> Tell me, how would you do something like a
> strcpy in such an environment?

	char *strcpy (to, from)
	register char *to, *from;
	{
		char *start = to;
		while ((*to++ = *from++)) != 0)
			;
		return start;
	}

But this would be with the understanding that a copy of a string in the
process of being changed might produce garbage; any process using strcpy()
to lengthen a string would be expected to plant a suitably located NUL first.
(Not necessarily at strlen(from)+to; at to+sizeof(tobuffer)-1 would do.)
If this isn't sufficient protection, then semaphores or the like become
appropriate.

> You should just say:  ``No one should use shared memory, unless
> he/she knows what they are doing''

Well, I can certainly agree with that.
Mark Brader