Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / examples / msg / io / file_unlink.c
1 /* Copyright (c) 2008-2010, 2012-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 /** @addtogroup MSG_examples
8  * 
9  * - <b>io/file_unlink.c</b> TBA
10  */
11
12 #define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.xml"
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include "msg/msg.h"
17 #include "surf/surf_private.h"
18
19 int host(int argc, char *argv[]);
20
21 XBT_LOG_NEW_DEFAULT_CATEGORY(io_file,
22                              "Messages specific for this io example");
23
24 int host(int argc, char *argv[])
25 {
26   msg_file_t file = NULL;
27   sg_size_t write;
28
29   // First open
30   XBT_INFO("\tOpen file '%s'",FILENAME1);
31   file = MSG_file_open(FILENAME1, NULL);
32
33   // Unlink the file
34   XBT_INFO("\tUnlink file '%s'",MSG_file_get_name(file));
35   MSG_file_unlink(file);
36
37   // Re Open the file wich is in fact created
38   XBT_INFO("\tOpen file '%s'",FILENAME1);
39   file = MSG_file_open(FILENAME1, NULL);
40
41   // Write into the new file
42   write = MSG_file_write(file,100000);  // Write for 100Ko
43   XBT_INFO("\tHave written %llu on %s",write,MSG_file_get_name(file));
44
45   // Write into the new file
46   write = MSG_file_write(file,100000);  // Write for 100Ko
47   XBT_INFO("\tHave written %llu on %s",write,MSG_file_get_name(file));
48
49   // Close the file
50   XBT_INFO("\tClose file '%s'",MSG_file_get_name(file));
51   MSG_file_close(file);
52
53   return 0;
54 }
55
56 int main(int argc, char **argv)
57 {
58   int res;
59   MSG_init(&argc, argv);
60   MSG_create_environment(argv[1]);
61   xbt_dynar_t hosts =  MSG_hosts_as_dynar();
62   MSG_function_register("host", host);
63   unsigned long nb_hosts = xbt_dynar_length(hosts);
64   XBT_INFO("Number of host '%lu'",nb_hosts);
65   char* name_host = xbt_strdup("0");
66   MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,0,msg_host_t) );
67   free(name_host);
68
69   xbt_dynar_free(&hosts);
70
71   res = MSG_main();
72   XBT_INFO("Simulation time %g", MSG_get_clock());
73   if (res == MSG_OK)
74     return 0;
75   else
76     return 1;
77
78 }