Welcome to mirror list, hosted at ThFree Co, Russian Federation.

platform_darwin.cc « src - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f02dc494a3959e291ea338ab4e8b2544f9896d64 (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
#include "node.h"
#include "platform.h"

#include <mach/task.h>
#include <mach/mach_init.h>
#include <mach-o/dyld.h> /* _NSGetExecutablePath */
#include <limits.h> /* PATH_MAX */

namespace node {
static char *process_title;

char** OS::SetupArgs(int argc, char *argv[]) {
  process_title = argc ? strdup(argv[0]) : NULL;
  return argv;
}


// OS::SetProcessTitle implemented in platform_darwin_proctitle.cc
}  // namespace node
#include "platform_darwin_proctitle.cc"
namespace node {


const char* OS::GetProcessTitle(int *len) {
  if (process_title) {
    *len = strlen(process_title);
    return process_title;
  }
  *len = 0;
  return NULL;
}

// Researched by Tim Becker and Michael Knight
// http://blog.kuriositaet.de/?p=257
int OS::GetMemory(size_t *rss, size_t *vsize) {
  struct task_basic_info t_info;
  mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;

  int r = task_info(mach_task_self(),
                    TASK_BASIC_INFO,
                    (task_info_t)&t_info,
                    &t_info_count);

  if (r != KERN_SUCCESS) return -1;

  *rss = t_info.resident_size;
  *vsize  = t_info.virtual_size;

  return 0;
}


int OS::GetExecutablePath(char* buffer, size_t* size) {
  uint32_t usize = *size;
  int result = _NSGetExecutablePath(buffer, &usize);
  if (result) return result;

  char *path = new char[2*PATH_MAX];

  char *fullpath = realpath(buffer, path);
  if (fullpath == NULL) {
    delete [] path;
    return -1;
  }
  strncpy(buffer, fullpath, *size);
  delete [] fullpath;
  *size = strlen(buffer);
  return 0;
}

}  // namespace node