× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Unix API's
  • From: Scott Klement <klemscot@xxxxxxxxxxxx>
  • Date: Fri, 25 Aug 2000 10:19:52 -0500 (CDT)



Hi...

Hmmm.. I don't normally use creat(), I use open() instead, so I had
to write a quick program to test creat() to see if it works for me.
It does.  The "quick program" is included, below.

Hope this helps.


On Fri, 25 Aug 2000, Mike Silvers wrote:

> I am having some troubles with the Unix API's.  I am trying to use the
> creat() API to create a stream file on the IFS.  I have found that the API
> Programming Reference manual is not helpful.  Has anyone used this API, or
> does anyone know of some good reference material for the Unix type API's?
> 
> Thanks
> 


     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* 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
     D   mode                        10U 0 Value

     D*--------------------------------------------------------------------
     D* Write to a file
     D*
     D* ssize_t write(int fildes, const void *buf, size_t bytes)
     D*--------------------------------------------------------------------
     D write           PR            10I 0 ExtProc('write')
     D  handle                       10I 0 value
     D  buffer                         *   value
     D  bytes                        10U 0 value

     D*--------------------------------------------------------------------
     D* Close a file
     D*
     D* int close(int fildes)
     D*--------------------------------------------------------------------
     D close           PR            10I 0 ExtProc('close')
     D  handle                       10I 0 value

     D* local variables:
     D path            S             80A
     D fd              S             10I 0
     D somedata        S            100A
     D Msg             S             50A

     C* creat() file:
     c                   eval      path = '/QOpenSys/testme.txt' + x'00'
     c                   eval      fd = creat(%addr(path): S_IRWXU)
     c                   if        fd < 0
     c                   eval      Msg = 'Unable to creat() file.'
     c                   dsply                   Msg
     c                   eval      *inlr = *on
     c                   return
     c                   endif

     C* write something to it:
     c                   eval      somedata = 'Some stuff to write to -
     c                             the file'
     c                   callp     write(fd:%addr(somedata):%size(somedata))

     C* close it:
     c                   callp     close(fd)

     c                   eval      *inlr = *on
     c                   return

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.