Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'coverity_scan' of github.com:mquinson/simgrid
[simgrid.git] / src / s4u / s4u_file.cpp
1 /* Copyright (c) 2015. The SimGrid Team. All rights reserved.               */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "xbt/log.h"
7 #include "src/msg/msg_private.h"
8 #include "src/msg/msg_mailbox.h"
9
10 #include "simgrid/s4u/actor.hpp"
11 #include "simgrid/s4u/comm.hpp"
12 #include "simgrid/s4u/host.hpp"
13 #include "simgrid/s4u/mailbox.hpp"
14
15 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files");
16
17 #include "simgrid/s4u/file.hpp"
18 #include "simgrid/s4u/host.hpp"
19 #include "simgrid/simix.h"
20
21 namespace simgrid {
22 namespace s4u {
23
24 File::File(const char*fullpath, void *userdata) {
25   // this cannot fail because we get a xbt_die if the mountpoint does not exist
26   p_inferior = simcall_file_open(fullpath, Host::current());
27   p_path = fullpath;
28 }
29
30 File::~File() {
31   simcall_file_close(p_inferior, Host::current());
32 }
33
34 sg_size_t File::read(sg_size_t size) {
35   return simcall_file_read(p_inferior, size, Host::current());
36 }
37 sg_size_t File::write(sg_size_t size) {
38   return simcall_file_write(p_inferior,size, Host::current());
39 }
40 sg_size_t File::size() {
41   return simcall_file_get_size(p_inferior);
42 }
43
44 void File::seek(sg_size_t pos) {
45   simcall_file_seek(p_inferior,pos,SEEK_SET);
46 }
47 sg_size_t File::tell() {
48   return simcall_file_tell(p_inferior);
49 }
50 void File::move(const char*fullpath) {
51   simcall_file_move(p_inferior,fullpath);
52 }
53 void File::unlink() {
54   sg_host_t attached = Host::current(); // FIXME: we should check where this file is attached
55   simcall_file_unlink(p_inferior,attached);
56 }
57
58 }} // namespace simgrid::s4u