summaryrefslogtreecommitdiff
path: root/ace/FILE.cpp
blob: b652c3da0aee5e2075bacdc4c9588276b4936917 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// FILE.cpp
// $Id$

/* Defines the member functions for the base class of the ACE_IO_SAP
   ACE_FILE abstraction. */

#include "ace/FILE.h"

#include "ace/OS_NS_unistd.h"
#include "ace/OS_NS_sys_stat.h"

#if !defined (__ACE_INLINE__)
#include "ace/FILE.i"
#endif /* __ACE_INLINE__ */

ACE_RCSID(ace, FILE, "$Id$")

ACE_ALLOC_HOOK_DEFINE(ACE_FILE)

void
ACE_FILE::dump (void) const
{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_FILE::dump");
  ACE_IO_SAP::dump ();
#endif /* ACE_HAS_DUMP */
}

// This is the do-nothing constructor.

ACE_FILE::ACE_FILE (void)
{
  ACE_TRACE ("ACE_FILE::ACE_FILE");
}

// Close the file

int
ACE_FILE::close (void)
{
  ACE_TRACE ("ACE_FILE::close");
  int result = 0;

  if (this->get_handle () != ACE_INVALID_HANDLE)
    {
      result = ACE_OS::close (this->get_handle ());
      this->set_handle (ACE_INVALID_HANDLE);
    }
  return result;
}

int
ACE_FILE::get_info (ACE_FILE_Info *finfo)
{
  ACE_TRACE ("ACE_FILE::get_info");
  ACE_stat filestatus;

  int result = ACE_OS::fstat (this->get_handle (),
                              &filestatus);

  if (result == 0)
    {
      finfo->mode_ = filestatus.st_mode;
      finfo->nlink_ = filestatus.st_nlink;
      finfo->size_ = filestatus.st_size;
    }

  return result;
}

int
ACE_FILE::get_info (ACE_FILE_Info &finfo)
{
  ACE_TRACE ("ACE_FILE::get_info");

  return this->get_info (&finfo);
}

int
ACE_FILE::truncate (off_t length)
{
  ACE_TRACE ("ACE_FILE::truncate");
  return ACE_OS::ftruncate (this->get_handle(), length);
}

off_t
ACE_FILE::seek (off_t offset, int startpos)
{
  return ACE_OS::lseek (this->get_handle (),
                        offset,
                        startpos);
}

off_t
ACE_FILE::position (long offset, int startpos)
{
  ACE_TRACE ("ACE_FILE::position");
  return this->seek (offset, startpos);
}

off_t
ACE_FILE::tell (void)
{
  ACE_TRACE ("ACE_FILE::tell");
  return ACE_OS::lseek (this->get_handle (), 0, SEEK_CUR);
}

off_t
ACE_FILE::position (void)
{
  ACE_TRACE ("ACE_FILE::position");
  return this->tell ();
}

// Return the local endpoint address.

int
ACE_FILE::get_local_addr (ACE_Addr &addr) const
{
  ACE_TRACE ("ACE_FILE::get_local_addr");

  // Perform the downcast since <addr> had better be an
  // <ACE_FILE_Addr>.
  ACE_FILE_Addr *file_addr =
    ACE_dynamic_cast (ACE_FILE_Addr *, &addr);

  if (file_addr == 0)
    return -1;
  else
    {
      *file_addr = this->addr_;
      return 0;
    }
}

// Return the same result as <get_local_addr>.

int
ACE_FILE::get_remote_addr (ACE_Addr &addr) const
{
  ACE_TRACE ("ACE_FILE::get_remote_addr");

  return this->get_local_addr (addr);
}

int
ACE_FILE::remove (void)
{
  ACE_TRACE ("ACE_FILE::remove");

  this->close ();
  return ACE_OS::unlink (this->addr_.get_path_name ());
}

int
ACE_FILE::unlink (void)
{
  ACE_TRACE ("ACE_FILE::unlink");

  return ACE_OS::unlink (this->addr_.get_path_name ());
}