From owner-freebsd-java@FreeBSD.ORG Thu Jun 4 05:14:46 2009 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 52BD11065673 for ; Thu, 4 Jun 2009 05:14:46 +0000 (UTC) (envelope-from malcolm.kay@internode.on.net) Received: from ipmail04.adl2.internode.on.net (ipmail04.adl2.internode.on.net [203.16.214.57]) by mx1.freebsd.org (Postfix) with ESMTP id D59068FC23 for ; Thu, 4 Jun 2009 05:14:45 +0000 (UTC) (envelope-from malcolm.kay@internode.on.net) Received: from ppp121-45-73-123.lns10.adl6.internode.on.net (HELO alpha.home) ([121.45.73.123]) by ipmail04.adl2.internode.on.net with ESMTP; 04 Jun 2009 14:29:30 +0930 From: Malcolm Kay Organization: at home To: freebsd-java@freebsd.org Date: Thu, 4 Jun 2009 14:29:29 +0930 User-Agent: KMail/1.8 References: <5CF2BB5045ED7D44B69F3E63642D693207E63FCF@ICE.scur.com> In-Reply-To: <5CF2BB5045ED7D44B69F3E63642D693207E63FCF@ICE.scur.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-6" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200906041429.29492.malcolm.kay@internode.on.net> Cc: "Deshmukh, Pramod" Subject: Re: Error while using strcat() in JNI X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Jun 2009 05:14:46 -0000 On Thu, 4 Jun 2009 07:08 am, Deshmukh, Pramod wrote: > Below is the c program which is called by java. Java passed > string object to this method which is converted to char *. > When I print using printf() function it prints the string > (char *), but strcat() does not like char *. > cmdOpenSsl = "echo -n "; Under modern versions of C literal strings often reside in program memory rather than data memory and therefore cannot be changed. (Memory exception) But even if your compiler places this string in data memory you have made no provision for space to add the suffix. Note also that in C, duplicate literal strings may be implemented as a single string so that if you do manage to change one then the other will also (mysteriously) change. So you need something like: char *cmdOpenSsl; cDesc=strdup(....); cmdOpenSsl=malloc(strlen("echo -n ")+strlen(cDesc)+1); strcpy(cmdOpenSsl,"echo -n "); strcat(cmdOpenSsl,cDesc); The problem would appear to have nothing to do with java. > > > Attached is the .h file the same. Please help me. Also I have > attached the .log file > > > > Thanks in Advance. > > > > --Pramod > Best of luck, Malcolm