monotone

monotone Mtn Source Tree

Root/platform.hh

1#ifndef __PLATFORM_HH__
2#define __PLATFORM_HH__
3
4// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13// this describes functions to be found, alternatively, in win32/* or unix/*
14// directories.
15
16
17#include <stdio.h>
18
19void read_password(std::string const & prompt, char * buf, size_t bufsz);
20void get_system_flavour(std::string & ident);
21bool is_executable(const char *path);
22
23// For LUA
24int existsonpath(const char *exe);
25int make_executable(const char *path);
26pid_t process_spawn(const char * const argv[]);
27pid_t process_spawn_redirected(char const * in,
28 char const * out,
29 char const * err,
30 char const * const argv[]);
31pid_t process_spawn_pipe(char const * const argv[], FILE** in, FILE** out);
32int process_wait(pid_t pid, int *res, int timeout = -1);// default infinite
33int process_kill(pid_t pid, int signal);
34int process_sleep(unsigned int seconds);
35
36// stop "\n"->"\r\n" from breaking automate on Windows
37void make_io_binary();
38
39#ifdef WIN32
40std::string munge_argv_into_cmdline(const char* const argv[]);
41#endif
42// for term selection
43bool have_smart_terminal();
44// this function cannot call W/P/L, because it is called by the tick printing
45// code.
46// return value of 0 means "unlimited"
47unsigned int terminal_width();
48
49// for "reckless mode" workspace change detection.
50// returns 'true' if it has generated a valid inodeprint; returns 'false' if
51// there was a problem, in which case we should act as if the inodeprint has
52// changed.
53class inodeprint_calculator
54{
55public:
56 template<typename T> void add_item(T obj)
57 {
58 size_t size(sizeof(obj));
59 add_item(&size, sizeof(size));
60 add_item(&obj, sizeof(obj));
61 }
62 // When adding a time to the print use these to note if it's
63 // close to the current time (within about 3 seconds) or
64 // in the future.
65 // To make this more robust, there are some tricks:
66 // -- we refuse to inodeprint files whose times are within a few seconds of
67 // 'now'. This is because, we might memorize the inodeprint, then
68 // someone writes to the file, and this write does not update the
69 // timestamp -- or rather, it does update the timestamp, but nothing
70 // happens, because the new value is the same as the old value. We use
71 // "a few seconds" to make sure that it is larger than whatever the
72 // filesystem's timekeeping granularity is (rounding to 2 seconds is
73 // known to exist in the wild).
74 // -- by the same reasoning, we should also refuse to inodeprint files whose
75 // time is in the future, because it is possible that someone will write
76 // to that file exactly when that future second arrives, and we will
77 // never notice. However, this would create persistent and hard to
78 // diagnosis slowdowns, whenever a tree accidentally had its times set
79 // into the future. Therefore, to handle this case, we include a "is
80 // this time in the future?" bit in the hashed information. This bit
81 // will change when we pass the future point, and trigger a re-check of
82 // the file's contents.
83 //
84 // This is, of course, still not perfect. There is no way to make our stat
85 // atomic with the actual read of the file, so there's always a race condition
86 // there. Additionally, this handling means that checkout will never actually
87 // inodeprint anything, but rather the first command after checkout will be
88 // slow. There doesn't seem to be anything that could be done about this.
89 virtual void note_future(bool f = true) = 0;
90 virtual void note_nowish(bool f = true) = 0;
91 virtual ~inodeprint_calculator() {};
92protected:
93 virtual void add_item(void *dat, size_t size) = 0;
94};
95bool inodeprint_file(std::string const & file, inodeprint_calculator & calc);
96
97// for netsync 'serve' pidfile support
98pid_t get_process_id();
99
100// netsync wants to ignore sigpipe; this is meaningless on Win32
101#ifdef WIN32
102inline void ignore_sigpipe() {}
103#else
104void ignore_sigpipe(); // in unix/process.cc
105#endif
106
107// filesystem stuff
108// FIXME: BUG: this returns a string in the filesystem charset/encoding
109std::string get_current_working_dir();
110// calls N() if fails
111void change_current_working_dir(std::string const & to);
112std::string tilde_expand(std::string const & path);
113std::string get_default_confdir();
114std::string get_homedir();
115namespace path
116{
117 typedef enum { nonexistent, directory, file } status;
118};
119path::status get_path_status(std::string const & path);
120
121struct dirent_consumer
122{
123 virtual ~dirent_consumer() {}
124 virtual void consume(const char *) = 0;
125};
126void do_read_directory(std::string const & path,
127 dirent_consumer & files,
128 dirent_consumer & dirs,
129 dirent_consumer & other_files);
130
131void rename_clobberingly(std::string const & from, std::string const & to);
132void do_remove(std::string const & path);
133
134void do_mkdir(std::string const & path);
135void write_data_worker(std::string const & p,
136 std::string const & dat,
137 std::string const & tmpdir,
138 bool user_private);
139
140// strerror wrapper for OS-specific errors (e.g. use FormatMessage on Win32)
141std::string os_strerror(os_err_t errnum);
142
143// for running cpu benchmarks
144// Returns the processor time used by the current process, plus some
145// arbitrary constant, measured in seconds.
146double cpu_now();
147
148// determine directory to load locale data from
149std::string get_locale_dir();
150
151#ifdef WIN32
152#include "win32/ssh_agent_platform.hh"
153#else
154#include "unix/ssh_agent_platform.hh"
155#endif
156
157// Local Variables:
158// mode: C++
159// fill-column: 76
160// c-file-style: "gnu"
161// indent-tabs-mode: nil
162// End:
163// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
164
165#endif // __PLATFORM_HH__

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status