Article View: comp.arch
Article #13732Re: String Handling -- strcpy() and shared memory
From: msb
Date: Mon, 20 Apr 1987 17:56
Date: Mon, 20 Apr 1987 17:56
31 lines
1577 bytes
1577 bytes
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
Technical Details
Message-ID:
<1987Apr20.125657.6693@sq.uucp>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!utfyzx!sq!msbReferences:
<15915@sun.uucp> <1987Apr1.121330.15976@sq.uucp> <573@csun.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!utgpu!utfyzx!sq!msb From: msb@sq.UUCP Newsgroups: comp.arch,comp.lang.c Subject: Re: String Handling -- strcpy() and shared memory Message-ID: <1987Apr20.125657.6693@sq.uucp> Date: Mon, 20-Apr-87 12:56:57 EST Article-I.D.: sq.1987Apr20.125657.6693 Posted: Mon Apr 20 12:56:57 1987 Date-Received: Wed, 22-Apr-87 03:26:48 EST References: <15915@sun.uucp> <1987Apr1.121330.15976@sq.uucp> <573@csun.UUCP> Reply-To: msb@sq.UUCP (Mark Brader) Organization: SoftQuad Inc., Toronto Lines: 31 Checksum: 38254