Blog Archive

Generate XML using RPGLE with help of C language API’ s Part 2

Click here to read the Tutorial from the beginning. Click here to download a copy of IFSIO_H

Source code for IFSIO_H courtesy of Scott C. Klement

Please check http://www.scottklement.com for latest source if this doesn't work !
/*
* Copyright (c) 2001 Scott C. Klement 
* All rights reserved. 
* 
* Redistribution and use in source and binary forms, with or without  
* modification, are permitted provided that the following conditions 
* are met: 
* 1. Redistributions of source code must retain the above copyright 
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* 
*/ 

* This header file contains the constants, structures and prototypes
* for using the Integrated File System API
*
* These APIs were designed originally for use in C programming.
* Therefore bear in mind:
* 1) All strings must be null-terminated, and variable-length.
* [ options(*string) will fix this for you ]
* 2) Errors are returned in the errno variable, and strings for
* them are available by calling strerror()
* 3) In order to call errno or strerror, you must bind to the
* QC2LE binding directory. See ERRNO_H for the definitions
* used to access errno.
*
* SCK 03/24/1999

* CHG SCK 03/28/2001 Added options(*string) & /define directives
* now that we're running a post-V4R2 system.

*
* To use these in your source code, you need a D-spec like this:
* D/COPY source-lib/QRPGLESRC,IFSIO_H

* IBM's "UNIX-type APIs" manual explains how to use all of these
* APIs in detail. However, the manual assumes you're writing
* your programs in C.

* This header file includes (in order)
* 1) Constants
* 2) Structures
* 3) Prototypes


D/if defined(IFSIO_H)
D/eof
D/endif

D/define IFSIO_H

D* ascii code-page
D CP_DOSASCII C 437
D CP_ASCII C 819

D**********************************************************************
D* Flags for use in open()
D*
D* More than one can be used -- add them together.
D**********************************************************************
D* Reading Only
D O_RDONLY C 1
D* Writing Only
D O_WRONLY C 2
D* Reading & Writing
D O_RDWR C 4
D* Create File if not exist
D O_CREAT C 8
D* Exclusively create
D O_EXCL C 16
D* Assign a CCSID
D O_CCSID C 32
D* Truncate File to 0 bytes
D O_TRUNC C 64
D* Append to File
D O_APPEND C 256
D* Synchronous write
D O_SYNC C 1024
D* Sync write, data only
D O_DSYNC C 2048
D* Sync read
D O_RSYNC C 4096
D* No controlling terminal
D O_NOCTTY C 32768
D* Share with readers only
D O_SHARE_RDONLY C 65536
D* Share with writers only
D O_SHARE_WRONLY C 131072
D* Share with read & write
D O_SHARE_RDWR C 262144
D* Share with nobody.
D O_SHARE_NONE C 524288
D* Assign a code page
D O_CODEPAGE C 8388608
D* Open in text-mode
D O_TEXTDATA C 16777216
D* Allow text translation
D* on newly created file.
D* Note: O_TEXT_CREAT requires all of the following flags to work:
D* O_CREAT+O_TEXTDATA+(O_CODEPAGE or O_CCSID)
D O_TEXT_CREAT C 33554432
D* Inherit mode from dir
D O_INHERITMODE C 134217728
D* Large file access
D* (for >2GB files)
D O_LARGEFILE C 536870912

D**********************************************************************
D* Access mode flags for access()
D*
D* F_OK = File Exists
D* R_OK = Read Access
D* W_OK = Write Access
D* X_OK = Execute or Search
D**********************************************************************
D F_OK C 0
D R_OK C 4
D W_OK C 2
D X_OK C 1

D**********************************************************************
D* Mode Flags.
D* basically, the mode parm of open(), creat(), chmod(),etc
D* uses 9 least significant bits to determine the
D* file's mode. (peoples access rights to the file)
D*
D* user: owner group other
D* access: R W X R W X R W X
D* bit: 8 7 6 5 4 3 2 1 0
D*
D* (This is accomplished by adding the flags below to get the mode)
D**********************************************************************
D* owner authority
D S_IRUSR C 256
D S_IWUSR C 128
D S_IXUSR C 64
D S_IRWXU C 448
D* group authority
D S_IRGRP C 32
D S_IWGRP C 16
D S_IXGRP C 8
D S_IRWXG C 56
D* other people
D S_IROTH C 4
D S_IWOTH C 2
D S_IXOTH C 1
D S_IRWXO C 7

D**********************************************************************
D* "whence" constants for use with lseek()
D**********************************************************************
D SEEK_SET C CONST(0)
D SEEK_CUR C CONST(1)
D SEEK_END C CONST(2)


D**********************************************************************
D* File Information Structure (stat)
D*
D* struct stat {
D* mode_t st_mode; /* File mode */
D* ino_t st_ino; /* File serial number */
D* nlink_t st_nlink; /* Number of links */
D* uid_t st_uid; /* User ID of the owner of file */
D* gid_t st_gid; /* Group ID of the group of file */
D* off_t st_size; /* For regular files, the file
D* * size in bytes */
D* time_t st_atime; /* Time of last access */
D* time_t st_mtime; /* Time of last data modification */
D* time_t st_ctime; /* Time of last file status change */
D* dev_t st_dev; /* ID of device containing file */
D* size_t st_blksize; /* Size of a block of the file */
D* unsigned long st_allocsize; /* Allocation size of the file */
D* qp0l_objtype_t st_objtype; /* AS/400 object type */
D* unsigned short st_codepage; /* Object data codepage */
D* char st_reserved1[66]; /* Reserved */
D* };
D*
D p_statds S *
D statds DS BASED(p_statds)
D st_mode 10U 0
D st_ino 10U 0
D st_nlink 5U 0
D st_pad 2A
D st_uid 10U 0
D st_gid 10U 0
D st_size 10I 0
D st_atime 10I 0
D st_mtime 10I 0
D st_ctime 10I 0
D st_dev 10U 0
D st_blksize 10U 0
D st_alctize 10U 0
D st_objtype 12A
D st_codepag 5U 0
D st_resv11 62A
D st_ino_gen_id 10U 0


D**********************************************************************
D* Group Information Structure (group)
D*
D* struct group {
D* char *gr_name; /* Group name. */
D* gid_t gr_gid; /* Group id. */
D* char **gr_mem; /* A null-terminated list of pointers
D* to the individual member names. */
D* };
D*
D p_group S *
D group DS Based(p_group)
D gr_name *
D gr_gid 10U 0
D gr_mem * DIM(256)


D**********************************************************************
D*
D* User Information Structure (passwd)
D*
D* (Don't let the name fool you, this structure does not contain
D* any password information. Its named after the UNIX file that
D* contains all of the user info. That file is "passwd")
D*
D* struct passwd {
D* char *pw_name; /* User name. */
D* uid_t pw_uid; /* User ID number. */
D* gid_t pw_gid; /* Group ID number. */
D* char *pw_dir; /* Initial working directory. */
D* char *pw_shell; /* Initial user program. */
D* };
D*
D p_passwd S *
D passwd DS BASED(p_passwd)
D pw_name *
D pw_uid 10U 0
D pw_gid 10U 0
D pw_dir *
D pw_shell *


D**********************************************************************
D* File Time Structure (utimbuf)
D*
D* struct utimbuf {
D* time_t actime; /* access time */
D* time_t modtime; /* modification time */
D* };
D*
D p_utimbuf S *
D utimbuf DS based(p_utimbuf)
D actime 10I 0
D modtime 10I 0


D**********************************************************************
D*
D* Directory Entry Structure (dirent)
D*
D* struct dirent {
D* char d_reserved1[16]; /* Reserved */
D* unsigned int d_reserved2; /* Reserved */
D* ino_t d_fileno; /* The file number of the file */
D* unsigned int d_reclen; /* Length of this directory entry
D* * in bytes */
D* int d_reserved3; /* Reserved */
D* char d_reserved4[8]; /* Reserved */
D* qlg_nls_t d_nlsinfo; /* National Language Information
D* * about d_name */
D* unsigned int d_namelen; /* Length of the name, in bytes
D* * excluding NULL terminator */
D* char d_name[_QP0L_DIR_NAME]; /* Name...null terminated */
D*
D* };
D*
D p_dirent s *
D dirent ds based(p_dirent)
D d_reserv1 16A
D d_reserv2 10U 0
D d_fileno 10U 0
D d_reclen 10U 0
D d_reserv3 10I 0
D d_reserv4 8A
D d_nlsinfo 12A
D nls_ccsid 10I 0 OVERLAY(d_nlsinfo:1)
D nls_cntry 2A OVERLAY(d_nlsinfo:5)
D nls_lang 3A OVERLAY(d_nlsinfo:7)
D nls_reserv 3A OVERLAY(d_nlsinfo:10)
D d_namelen 10U 0
D d_name 640A



D*--------------------------------------------------------------------
D* Determine file accessibility
D*
D* int access(const char *path, int amode)
D*
D*--------------------------------------------------------------------
D access PR 10I 0 ExtProc('access')
D Path * Value Options(*string)
D amode 10I 0 Value

D*--------------------------------------------------------------------
D* Change Directory
D*
D* int chdir(const char *path)
D*--------------------------------------------------------------------
D chdir PR 10I 0 ExtProc('chdir')
D path * Value Options(*string)

D*--------------------------------------------------------------------
D* Change file authorizations
D*
D* int chmod(const char *path, mode_t mode)
D*--------------------------------------------------------------------
D chmod PR 10I 0 ExtProc('chmod')
D path * Value options(*string)
D mode 10U 0 Value

D*--------------------------------------------------------------------
D* Change Owner/Group of File
D*
D* int chown(const char *path, uid_t owner, gid_t group)
D*--------------------------------------------------------------------
D chown PR 10I 0 ExtProc('chown')
D path * Value options(*string)
D owner 10U 0 Value
D group 10U 0 Value

D*--------------------------------------------------------------------
D* Close a file
D*
D* int close(int fildes)
D*
D* Note: Because close() is already defined in socket_h, we use
D* "closef" here to prevent a conflict. Now, in V4, we
D* can do the same thing with conditional compilation, so
D* "close" is also defined.
D*--------------------------------------------------------------------
D closef PR 10I 0 ExtProc('close')
D handle 10I 0 value

D/if not defined(CLOSE_PROTOTYPE)
D close PR 10I 0 ExtProc('close')
D handle 10I 0 value
D/define CLOSE_PROTOTYPE
D/endif

D*--------------------------------------------------------------------
D* Close a directory
D*
D* int closedir(DIR *dirp)
D*--------------------------------------------------------------------
D closedir PR 10I 0 EXTPROC('closedir')
D dirhandle * VALUE

D*--------------------------------------------------------------------
D* Create or Rewrite File
D*
D* int creat(const char *path, mode_t mode)
D*--------------------------------------------------------------------
D creat PR 10I 0 ExtProc('creat')
D path * Value options(*string)
D mode 10U 0 Value

D*--------------------------------------------------------------------
D* Duplicate open file descriptor
D*
D* int dup(int fildes)
D*--------------------------------------------------------------------
D dup PR 10I 0 ExtProc('dup')
D fildes 10I 0 Value

D*--------------------------------------------------------------------
D* Duplicate open file descriptor to another descriptor
D*
D* int dup2(int fildes, int fildes2)
D*--------------------------------------------------------------------
D dup2 PR 10I 0 ExtProc('dup2')
D fildes 10I 0 Value
D fildes2 10I 0 Value

D*--------------------------------------------------------------------
D* Change file authorizations by descriptor
D*
D* int fchmod(int fildes, mode_t mode)
D*--------------------------------------------------------------------
D fchmod PR 10I 0 ExtProc('fchmod')
D fildes 10I 0 Value
D mode 10U 0 Value

D*--------------------------------------------------------------------
D* Change Owner and Group of File by Descriptor
D*
D* int fchown(int fildes, uid_t owner, gid_t group)
D*--------------------------------------------------------------------
D fchown PR 10I 0 ExtProc('fchown')
D fildes 10I 0 Value
D owner 10U 0 Value
D group 10U 0 Value

D*--------------------------------------------------------------------

Click here for the next Chapter


Recommended Reading


2 comments :