|
There is one consideration to using getpwnam() that may not be obvious.
The returned path is in the CCSID of the current job and there can be data
loss if elements of the path associated with the user profile contain
characters not in your current CCSID. If you intend to work only with one
language environment on your system then this may be OK.
QSYRUSRI is not as straight forward for some users to use as it returns the
path in Unicode, but the use of Unicode is what also allows the application
to retrieve the path without worrying about what CCSID might be in use at
the current time. For developers writing generic routines that may run
anywhere in the world the use of Unicode does actually simplify their
development effort.
Bruce Vining
Scott Klement
<rpg400-l@scottkl
ement.com> To
Sent by: RPG programming on the AS400 /
rpg400-l-bounces@ iSeries <rpg400-l@xxxxxxxxxxxx>
midrange.com cc
Subject
03/18/2005 01:30 Re: Data translation question
AM
Please respond to
RPG programming
on the AS400 /
iSeries
> I am calling API QSYRUSRI to get the user profile Home Directory, but the
> structure that the info comes back into has the directory name formatted
as
> CCSID 1200.
You can use the iconv() API to translate the result. There should be
examples of calling the iconv() API in the archives, I'm pretty sure I've
posted some before. If you can't find any, let me know.
Personally, I'd use the getpwnam() API to get the home directory. It's
just easier to use. Here's an example of an RPG program that's intended to
be called by CL to get a user's home directory:
H DFTACTGRP(*NO)
D passwd DS qualified
D BASED(Template)
D pw_name *
D pw_uid 10U 0
D pw_gid 10U 0
D pw_dir *
D pw_shell *
D getpwnam PR * ExtProc('getpwnam')
D name * Value options(*string)
D p_info s *
D info ds likeds(passwd)
D based(p_info)
D peUser s 10A
D peHomeDir s 256A
C *entry plist
c parm peUser
c parm peHomeDir
c eval p_info = getpwnam(%trimr(peUser))
c if p_info = *NULL
c*** error occurred. Check errno to find out what went wrong.
c endif
c eval peHomedir = %str(info.pw_dir)
c return
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.