delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/08/03/11:49:53

X-Spam-Check-By: sourceware.org
Message-ID: <44D21B14.2060404@scytek.de>
Date: Thu, 03 Aug 2006 11:49:40 -0400
From: Volker Quetschke <quetschke AT scytek DOT de>
User-Agent: Thunderbird 1.5.0.5 (Windows/20060719)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Is casting away const OK for cygwin's execvp
References: <44D21A8E DOT 7090708 AT scytek DOT de>
In-Reply-To: <44D21A8E.7090708@scytek.de>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------enig9271D2A76EB5BFF19A51CB71
Content-Type: multipart/mixed;
 boundary="------------030306040308050704040207"

This is a multi-part message in MIME format.
--------------030306040308050704040207
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Volker Quetschke wrote:
> Basically (see the attached example program)

D'oh! I forgot the attachment.

  Volker

--=20
PGP/GPG key  (ID: 0x9F8A785D)  available  from  wwwkeys.de.pgp.net
key-fingerprint 550D F17E B082 A3E9 F913  9E53 3D35 C9BA 9F8A 785D

--------------030306040308050704040207
Content-Type: text/plain;
 name="execvptest.cc"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
 filename="execvptest.cc"

#include <string>
#include <iostream>
#include <cstddef>
#include <cerrno>

using std::string;
using std::size_t;

int main() {

  const char *nargv[3];

  string arg1("echo");
  nargv[0] =3D arg1.c_str();

  string arg2("test");
  nargv[1] =3D arg2.c_str();

  nargv[2] =3D NULL;

  // Unfortunately the prototype of execvp does not like const char*,
  // actually not const char* nargv[] coming from .c_str(). So either
  // we copy everything into newly allocated variables or we force it
  // with a cast. const_cast<char * const *>() - Is this OK?
  if ( execvp(nargv[0], const_cast<char * const *>(nargv) ) < 0 ) {
    perror("Execvp error.  Aborting.");
    exit(1);=20=20=20=20=20=20=20
  }
  return 1;
}

--------------030306040308050704040207--

--------------enig9271D2A76EB5BFF19A51CB71
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (MinGW)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFE0hsUPTXJup+KeF0RAgC0AKDJD1AhhyuGwRFNQdGv9Q8pXL2ffQCgu5d9
edqKJS9sIML677yF97zoH50=
=vExI
-----END PGP SIGNATURE-----

--------------enig9271D2A76EB5BFF19A51CB71--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019