C++ for z/OS, bad return code on rename()

J

Jerry Orr

I'm writing a simple JNI C++ function on a z/OS 1.4 system. I am
attempting to rename a dataset; however, when I use the rename()
function, I get a return code of -1. All of the return codes listed in
the "C/C++ Runtime Library Reference" (EACCES, EINVAL, etc) are
positive integers, and all of them can be successfully input into
strerror() to get a valid error message. Passing -1 to strerror(),
though, just returns a null string.

Has anyone experienced anything similar to this? I'm not sure why I'd
be getting -1 as a return code, and I've been unable to find anything
about it in the manuals or on the web.

Here's an example of my method:

/* This is the signature for a JNI method */
JNIEXPORT jint JNICALL
Java_DatasetUtilities_nativeRenameDataset
(JNIEnv *env, jclass obj, jstring jfrom, jstring jto)
{
int rc;
/* This is JNI code to convert the ASCII Java strings into EBCDIC */
const char *from = (*env)->GetStringUTFChars(env, jfrom, 0);
const char *to = (*env)->GetStringUTFChars(env, jto, 0);
__atoe(from);
__atoe(to);

/* Here, rename() is returning -1 */
rc = rename(from, to);

/* This is just printing out -1 and an empty string */
printf("rename() error (error code: %i, error message: %s)\n",
rc, strerror(rc));

/* More JNI code */
(*env)->ReleaseStringUTFChars(env, jfrom, from);
(*env)->ReleaseStringUTFChars(env, jto, to);

return rc;
}
 
O

Owen Jacobson

I'm writing a simple JNI C++ function on a z/OS 1.4 system. I am
attempting to rename a dataset; however, when I use the rename()
function, I get a return code of -1. All of the return codes listed in
the "C/C++ Runtime Library Reference" (EACCES, EINVAL, etc) are
positive integers, and all of them can be successfully input into
strerror() to get a valid error message. Passing -1 to strerror(),
though, just returns a null string.

Psst: check the value of errno if the fuction returns -1. This is
somewhat off-topic here; try c.l.c for standard C (which rename () might
be) or a discussion group for z/OS.
 
J

Jack Klein

I'm writing a simple JNI C++ function on a z/OS 1.4 system. I am
attempting to rename a dataset; however, when I use the rename()
function, I get a return code of -1. All of the return codes listed in
the "C/C++ Runtime Library Reference" (EACCES, EINVAL, etc) are
positive integers, and all of them can be successfully input into
strerror() to get a valid error message. Passing -1 to strerror(),
though, just returns a null string.

Has anyone experienced anything similar to this? I'm not sure why I'd
be getting -1 as a return code, and I've been unable to find anything
about it in the manuals or on the web.

[snip off-topic java code]

What you have here is not a C++ language issue at all.

You are calling a Java function named remove() in a Java program.
Java is completely off-topic here. Just because Java provides a
function with the name of a standard C and C++ library function does
not make this a C or C++ question.
 
J

Jerry Orr

This thread is a little old now, but I just want to make sure anyone
reading this in the future can clearly see that it is you, not I, that
is the idiot.
You are calling a Java function named remove() in a Java program.

No. I am calling the C function remove() from a C program; I just
happen to be using JNI to call my C program from a Java program.
Java is completely off-topic here.

Yes, it is. That, however, is beside the point, as this is not a Java
question. I simply mentioned Java to provide background as to what I
am doing.
Just because Java provides a
function with the name of a standard C and C++ library function does
not make this a C or C++ question.

You clearly have no experience in Java, or you would have been able to
quickly realize that the code I displayed was NOT Java, and I'm a
little skeptical about your C/C++ experience if you did not recongnize
that it IS C code.

At any rate, for anyone who may be interested (or for future
seachers), my problem was simply that I was running strerror() on the
return code, when I actually needed to run it on errcode. A silly
mistake that caused me a lot of headache.

Jack Klein said:
I'm writing a simple JNI C++ function on a z/OS 1.4 system. I am
attempting to rename a dataset; however, when I use the rename()
function, I get a return code of -1. All of the return codes listed in
the "C/C++ Runtime Library Reference" (EACCES, EINVAL, etc) are
positive integers, and all of them can be successfully input into
strerror() to get a valid error message. Passing -1 to strerror(),
though, just returns a null string.

Has anyone experienced anything similar to this? I'm not sure why I'd
be getting -1 as a return code, and I've been unable to find anything
about it in the manuals or on the web.

[snip off-topic java code]

What you have here is not a C++ language issue at all.

You are calling a Java function named remove() in a Java program.
Java is completely off-topic here. Just because Java provides a
function with the name of a standard C and C++ library function does
not make this a C or C++ question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,479
Latest member
JaysonK723

Latest Threads

Top