[comp.unix.aix] sprintf

biorn@FKRS1.PHC.CHALMERS.SE (Bjorn Sandell) (06/08/91)

Is the function sprintf() doing what is't supposed to?
I have my doubts, but no evidence...

Bjorn

allender@ux1.cso.uiuc.edu (Mark Allender) (06/11/91)

In article <9106081543.AA09685@fkrs1.phc.chalmers.se>, biorn@FKRS1.PHC.CHALMERS.SE (Bjorn Sandell) writes:
|> 
|> Is the function sprintf() doing what is't supposed to?
|> I have my doubts, but no evidence...
|> 
|> Bjorn

Could we have a little more information?  This is kind of lacking in what
you are asking...what is the problem that you are encountering, what
platform, what level of AIX.....?????

-- 
-Mark Allender
-University of Illinois at Urbana/Champaign
-Conversation Builder Project
-allender@cs.uiuc.edu

jona@iscp.Bellcore.COM (Jon Alperin) (06/11/91)

Try changing the xxxxx's to CAPITAL letters. They may be trying to create a temporary file using the mktemp() call, which replaces the 6 CAPITAL X's with the PID of the process and a unique alphabetic character.

-- 
Jon Alperin
Bell Communications Research

---> Internet: jona@iscp.bellcore.com
---> Voicenet: (908) 699-8674
---> UUNET: uunet!bcr!jona

* All opinions and stupid questions are my own *

abe@mace.cc.purdue.edu (Vic Abell) (06/11/91)

In article <9106120920.AA08552@fkrs1.phc.chalmers.se>
biorn@FKRS1.PHC.CHALMERS.SE (Bjorn Sandell) asks about sprintf's
that return char *.

For you, Bjorn, the unpleasant reality is that current standards call
for sprintf to return an integer, so you are going to have to convert
any code that expects a character pointer return from sprintf.

Versions of sprintf that return a character pointer to the target
buffer are fast becoming obsolete.  This is true of POSIX, and the
versions of System V and BSD from which AIX descends.

biorn@FKRS1.PHC.CHALMERS.SE (Bjorn Sandell) (06/12/91)

Let's se if I can be more specific :)

First a "disclaimer": I don't know much AIX and even less C.

This is a 320 machine and uname -a says AIX fkrs1 1 3 000023913100.

I'm trying to port xmail. It usally coredumps, but once I got an error
message saying something like "can't open file /tmp/tmpxxxx_" where
xxxx was a number.
After some browsing through the sorce files I (think I) found the line
where this filename should be created. It was a sprintf statement, and I've
tried to replace it with strcpy and strcat as follows:

/* if ((fp = fopen((char *)sprintf(s, "%s_", tmpName), "w")) != NULL) {*/
   strcpy(s,tmpName);
      strcat(s,"_");
       if ((fp = fopen(s, "w")) != NULL) {

Now it seems to find the /tmp/tmpxxxx_ file (no errors at least;),
but it eventually coredumps anyway.
The question is do I have to rewrite all sprintf's this way or is there an
easier way? Is there anything wrong at all with the original line?
Any and all help is welcome!

Bjorn


 ZDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD?
 3 But, but, everyone KNOWS that all the answers can be found in manuals!    3
 3 Don't you still have your copy of "Life: A User's Manual", that came with 3
 3 your wetware? :)                                                          3
 @DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDY