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

Archive Download this file

Branches

Tags

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