posix_rename Function

private function posix_rename(oldpath, newpath) result(rc)

Atomically rename oldpath -> newpath via libc rename(2). Returns 0 on success, -1 on error.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: oldpath
character(len=*), intent(in) :: newpath

Return Value integer


Calls

proc~~posix_rename~~CallsGraph proc~posix_rename posix_rename none~c_rename c_rename proc~posix_rename->none~c_rename proc~string_to_c string_to_c proc~posix_rename->proc~string_to_c

Called by

proc~~posix_rename~~CalledByGraph proc~posix_rename posix_rename proc~ocean_restart_write_local ocean_restart_write_local proc~ocean_restart_write_local->proc~posix_rename proc~ocean_state_restart_write ocean_state_restart_write proc~ocean_state_restart_write->proc~ocean_restart_write_local proc~ocean_state_restart_write_drop_field ocean_state_restart_write_drop_field proc~ocean_state_restart_write_drop_field->proc~ocean_restart_write_local proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~ocean_state_restart_write proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean

Variables

Type Visibility Attributes Name Initial
character(kind=c_char, len=1), private, allocatable, target :: c_new(:)
character(kind=c_char, len=1), private, allocatable, target :: c_old(:)

Interfaces

interface

  • function c_rename(old, new) result(r) bind(C, name="rename"))

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in), value :: old
    type(c_ptr), intent(in), value :: new

    Return Value integer(kind=c_int)


Source Code

   integer function posix_rename(oldpath, newpath) result(rc)
      !! Atomically rename `oldpath` -> `newpath` via libc `rename(2)`.
      !! Returns 0 on success, -1 on error.
      character(len=*), intent(in) :: oldpath, newpath
      ! Null-terminated C strings as `target` locals so `c_loc` can hand
      ! libc `rename` a pointer to each (c_ptr by value sidesteps
      ! assumed-size dummies).
      character(kind=c_char), allocatable, target :: c_old(:), c_new(:)
      interface
         function c_rename(old, new) bind(C, name="rename") result(r)
            import :: c_ptr, c_int
            implicit none
            type(c_ptr), value, intent(in) :: old
            type(c_ptr), value, intent(in) :: new
            integer(c_int) :: r
         end function c_rename
      end interface
      c_old = string_to_c(oldpath)
      c_new = string_to_c(newpath)
      rc = int(c_rename(c_loc(c_old), c_loc(c_new)))
   end function posix_rename