xref: /PHP-7.0/sapi/cli/php_cli_process_title.c (revision 478f119a)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2017 The PHP Group                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Author: Keyur Govande (kgovande@gmail.com)                           |
16   +----------------------------------------------------------------------+
17 */
18 
19 /* $Id$ */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include "php.h"
26 #include "php_cli_process_title.h"
27 #include "ps_title.h"
28 
29 /* {{{ proto boolean cli_set_process_title(string arg)
30    Return a boolean to confirm if the process title was successfully changed or not */
PHP_FUNCTION(cli_set_process_title)31 PHP_FUNCTION(cli_set_process_title)
32 {
33     char *title = NULL;
34     size_t title_len;
35     int rc;
36 
37     if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &title, &title_len) == FAILURE) {
38         return;
39     }
40 
41     rc = set_ps_title(title);
42     if (rc == PS_TITLE_SUCCESS) {
43         RETURN_TRUE;
44     }
45 
46     php_error_docref(NULL, E_WARNING, "cli_set_process_title had an error: %s", ps_title_errno(rc));
47     RETURN_FALSE;
48 }
49 /* }}} */
50 
51 /* {{{ proto string cli_get_process_title()
52    Return a string with the current process title. NULL if error. */
PHP_FUNCTION(cli_get_process_title)53 PHP_FUNCTION(cli_get_process_title)
54 {
55         int length = 0;
56         const char* title = NULL;
57         int rc;
58 
59         if (zend_parse_parameters_none() == FAILURE) {
60             return;
61         }
62 
63         rc = get_ps_title(&length, &title);
64         if (rc != PS_TITLE_SUCCESS) {
65                 php_error_docref(NULL, E_WARNING, "cli_get_process_title had an error: %s", ps_title_errno(rc));
66                 RETURN_NULL();
67         }
68 
69         RETURN_STRINGL(title, length);
70 }
71 /* }}} */
72 
73 /*
74  * Local variables:
75  * tab-width: 4
76  * c-basic-offset: 4
77  * End:
78  * vim600: noet sw=4 ts=4 fdm=marker
79  * vim<600: noet sw=4 ts=4
80  */
81