home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / ixemul-39.47-env-bin.lha / man / cat3 / directory.0 < prev    next >
Text File  |  1993-12-07  |  4KB  |  133 lines

  1.  
  2. DIRECTORY(3)               UNIX Programmer's Manual               DIRECTORY(3)
  3.  
  4. NNAAMMEE
  5.      ooppeennddiirr, rreeaaddddiirr, tteellllddiirr, sseeeekkddiirr, rreewwiinnddddiirr, cclloosseeddiirr, ddiirrffdd - directo­
  6.      ry operations
  7.  
  8. SSYYNNOOPPSSIISS
  9.      ##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
  10.      ##iinncclluuddee <<ddiirreenntt..hh>>
  11.  
  12.      _D_I_R _*
  13.      ooppeennddiirr(_c_o_n_s_t _c_h_a_r _*_f_i_l_e_n_a_m_e)
  14.  
  15.      _s_t_r_u_c_t _d_i_r_e_c_t
  16.      rreeaaddddiirr(_D_I_R _*_d_i_r_p)
  17.  
  18.      _l_o_n_g
  19.      tteellllddiirr(_c_o_n_s_t _D_I_R _*_d_i_r_p)
  20.  
  21.      _v_o_i_d
  22.      sseeeekkddiirr(_D_I_R _*_d_i_r_p, _l_o_n_g _l_o_c)
  23.  
  24.      _v_o_i_d
  25.      rreewwiinnddddiirr(_D_I_R _*_d_i_r_p)
  26.  
  27.      _i_n_t
  28.      cclloosseeddiirr(_D_I_R _*_d_i_r_p)
  29.  
  30.      _i_n_t
  31.      ddiirrffdd(_D_I_R _*_d_i_r_p)
  32.  
  33. DDEESSCCRRIIPPTTIIOONN
  34.      The ooppeennddiirr() function opens the directory named by _f_i_l_e_n_a_m_e, associates
  35.      a _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m with it and returns a pointer to be used to identify
  36.      the _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m in subsequent operations.  The pointer NULL is re­
  37.      turned if _f_i_l_e_n_a_m_e cannot be accessed, or if it cannot malloc(3) enough
  38.      memory to hold the whole thing.
  39.  
  40.      The rreeaaddddiirr() function returns a pointer to the next directory entry.  It
  41.      returns NULL upon reaching the end of the directory or detecting an in­
  42.      valid sseeeekkddiirr() operation.
  43.  
  44.      The tteellllddiirr() function returns the current location associated with the
  45.      named _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m.
  46.  
  47.      The sseeeekkddiirr() function sets the position of the next rreeaaddddiirr() operation
  48.      on the _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m. The new position reverts to the one associated
  49.      with the _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m when the tteellllddiirr() operation was performed.
  50.      Values returned by tteellllddiirr() are good only for the lifetime of the DIR
  51.      pointer, _d_i_r_p, from which they are derived.  If the directory is closed
  52.      and then reopened, the tteellllddiirr() value may be invalidated due to unde­
  53.      tected directory compaction.  It is safe to use a previous tteellllddiirr() val­
  54.      ue immediately after a call to ooppeennddiirr() and before any calls to
  55.      rreeaaddddiirr().
  56.  
  57.      The rreewwiinnddddiirr() function resets the position of the named _d_i_r_e_c_t_o_r_y
  58.      _s_t_r_e_a_m to the beginning of the directory.
  59.  
  60.      The cclloosseeddiirr() function closes the named _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m and frees the
  61.      structure associated with the _d_i_r_p pointer, returning 0 on success.  On
  62.      failure, -1 is returned and the global variable _e_r_r_n_o is set to indicate
  63.      the error.
  64.  
  65.  
  66.      The ddiirrffdd() function returns the integer file descriptor associated with
  67.      the named _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m, see open(2).
  68.  
  69.      Sample code which searchs a directory for entry ``name'' is:
  70.  
  71.            len = strlen(name);
  72.            dirp = opendir(".");
  73.            for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
  74.                    if (dp­>d_namlen == len && !strcmp(dp­>d_name, name)) {
  75.                            (void)closedir(dirp);
  76.                            return FOUND;
  77.                    }
  78.            (void)closedir(dirp);
  79.            return NOT_FOUND;
  80.  
  81. SSEEEE AALLSSOO
  82.      open(2),  close(2),  read(2),  lseek(2),  dir(5)
  83.  
  84. HHIISSTTOORRYY
  85.      The ooppeennddiirr(), rreeaaddddiirr(), tteellllddiirr(), sseeeekkddiirr(), rreewwiinnddddiirr(), cclloosseeddiirr(),
  86.      and ddiirrffdd() functions appeared in 4.2BSD.
  87.  
  88. 4.2 Berkeley Distribution       April 19, 1991                               2
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.