🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #39452

more on strncpy (was re: laser c question)

#39452
From: Sam Alan EZUST
Date: Thu, 14 Dec 1989 02:16
93 lines
4423 bytes
Here is a private letter I wanted to send but it got bounced, 
but I realize it should be posted publicly for some of its
content anyway.

>>> DATA
<<< 554 <john%stag.UUCP%uunet.UUCP%dynasoft@Larry.McRCIM.McGill.EDU>... Remote protocol error: Bad file number
554 john%stag.UUCP%uunet.UUCP%dynasoft@Larry.McRCIM.McGill.EDU... Service unavailable


[In message "Re: laser C question" on Dec 13, John Stanley writes:]
: [in my message I wrote:] 
: > Since there is no mem.h library of routines, I use strncpy to copy the
: > contents of one-dimensional arrays.
: 
:   Since strncpy doesn't copy <n> bytes but rather <n> bytes OR until it
: finds the 1st null (zero) byte in the array, using strncpy to replace
: blkcpy or memcpy isn't going to work.  If it has worked so-far, it's only
: because Laser C uses an incorrect implementation of strncpy or because
: you've been Very-Very lucky....

no, actually. This little fact was something I knew a little while ago
but totally forgot about until two days ago, while I was agonizing over
the strangest bug for four damned hours and finally found it after
exhausting every other goddamned possibility... Too bad your letter didn't
come two days earlier, but that's not your fault :-)..

:   Moving one, two, or fifty dimensional arrays is all the same to C.
: It's just a destination address, a source address, and the number of
: bytes to move...


:   I can send you one that's written for Alcyon/Sozobon C in assembly.
: It's quite fast but you'd probably have to modify it a little to be
: compatable with Lazer C.  I could also send you a similar block-move
: function written entirely in C (it just wouldn't be quite-as-fast).

someone already sent me dlibs memcpy which I believe is what is used
in Sozobon.... However, I don't have an assembler and am not too
much of an expert in it anyway, so I couldn't get it installed on
my system without help.


:   Alternately, does Lazer C allow copying structures using a simple
: assignment?  <struct2> = <struct1>;  If so, what I've ocassionaly used in
: situations like yours is to define a struct containing the array and
: moved copys of the array arround by just using assignments...

that's a good idea. I should try it. I didn't think it was possible though,
as struct names are just pointers to memory locations of data, just
like arrays, and you can address the 5th byte of a structure with
*(structname+5) just like arrays.

 in reply to my using strncpy for multidimension arrays not working,

:   Why won't it?  Ignoring for the moment that strncpy isn't a blkcpy or
: memcpy, what's wrong with specifiying &array[0][0] as the address and
: using the size of the entire array (assuming it's smaller than 64k bytes)
: as the length?

I think I tried it and got a compiler error.. I could be mistaken, but
I passed it just 

array

instead of

&(array[0][0])
since I thought the two were equivalent pointers...


:   I'm trying...  What you wrote makes it sound like you've been making
: some bad guesses so far so it may take a bit of work to get your program
: working the way you want it to...  What are you writing anyway?

you are exactly right. However, I got it working now via the brute-force
loop-of-assign statements. If I can get dlibs installed properly on
Laser C (and I am having trouble, as you will soon see in one of 
my messages posted on c-s-a-st which I posted today), I will then
translate them all into memcpy's.

:   .. although, it would be a real-good-idea if you posted a note on the
: net mentioning that strncpy doesn't move <n> bytes so other beginning
: programmers who see your message won't think that it's a correct
: substitution....

ok.. I shall. Thanks for your help/reply!!



-- 
S. Alan Ezust                                   depeche@calvin.cs.mcgill.ca
McGill University Department of Computer Science - Montreal, Quebec, Canada
Technical Details
Message-ID: <1870@calvin.cs.mcgill.ca>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!clyde.concordia.ca!mcgill-vision!quiche!calvin!depeche

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!clyde.concordia.ca!mcgill-vision!quiche!calvin!depeche
From: depeche@quiche.cs.mcgill.ca (Sam Alan EZUST)
Newsgroups: comp.sys.atari.st
Subject: more on strncpy (was re: laser c question)
Message-ID: <1870@calvin.cs.mcgill.ca>
Date: 14 Dec 89 02:16:10 GMT
Reply-To: depeche@calvin.cs.mcgill.ca (Sam Alan EZUST)
Organization: SOCS, McGill University, Montreal, Canada
Lines: 93