Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_support.c File Reference

Collects shared low-level helpers for buffers, strings, path manipulation, file reads, and simple path predicates. More...

#include "native_support.h"
#include <ctype.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>

Go to the source code of this file.

Macros

#define PHAROS_SUPPORT_PATH_SEP   '/'
#define pharos_support_getcwd   getcwd
#define pharos_support_access   access
#define pharos_support_stat   stat
#define pharos_support_strdup   strdup

Functions

void buffer_init (Buffer *buffer)
 Initializes a growable buffer to an empty state.
void buffer_free (Buffer *buffer)
 Releases memory owned by a growable buffer.
int buffer_reserve (Buffer *buffer, size_t needed)
 Ensures a buffer can hold at least a requested number of bytes.
int buffer_append (Buffer *buffer, const void *data, size_t len)
 Appends bytes to a growable buffer and maintains a trailing NUL byte.
char * dup_range (const char *start, size_t len)
 Duplicates a byte range into a newly allocated NUL-terminated string.
void trim_in_place (char *text)
 Trims leading and trailing ASCII whitespace from a string in place.
int starts_with (const char *value, const char *prefix)
 Tests whether one string starts with another string.
int streq (const char *a, const char *b)
 Tests whether two strings are exactly equal.
char * path_join (const char *left, const char *right)
 Joins two path segments using the native path separator.
char * path_dirname (const char *path)
 Returns the parent directory component of a path.
int path_exists (const char *path)
 Tests whether a filesystem path currently exists.
int path_is_directory (const char *path)
 Tests whether a filesystem path refers to a directory.
int path_is_writable (const char *path)
 Tests whether a filesystem path is writable by the current process.
char * path_canonicalize (const char *path)
 Normalizes a path by collapsing redundant separators and dot segments.
char * resolve_relative_to (const char *base_dir, const char *value)
 Resolves a path value relative to a base directory when needed.
char * current_working_directory (void)
 Returns the current working directory.
char * read_file_text (const char *path)
 Reads an entire file into a newly allocated text buffer.

Detailed Description

Collects shared low-level helpers for buffers, strings, path manipulation, file reads, and simple path predicates.

Definition in file native_support.c.

Macro Definition Documentation

◆ pharos_support_access

#define pharos_support_access   access

Definition at line 29 of file native_support.c.

Referenced by path_exists(), and path_is_writable().

◆ pharos_support_getcwd

#define pharos_support_getcwd   getcwd

Definition at line 28 of file native_support.c.

Referenced by current_working_directory().

◆ PHAROS_SUPPORT_PATH_SEP

#define PHAROS_SUPPORT_PATH_SEP   '/'

Definition at line 27 of file native_support.c.

Referenced by path_canonicalize(), path_dirname(), and path_join().

◆ pharos_support_stat

#define pharos_support_stat   stat

Definition at line 30 of file native_support.c.

Referenced by path_is_directory().

◆ pharos_support_strdup

#define pharos_support_strdup   strdup

Function Documentation

◆ buffer_append()

◆ buffer_free()

◆ buffer_init()

◆ buffer_reserve()

int buffer_reserve ( Buffer * buffer,
size_t needed )

Ensures a buffer can hold at least a requested number of bytes.

Parameters
bufferBuffer whose capacity may grow.
neededMinimum required capacity in bytes.
Returns
0 on success, or -1 on allocation or overflow failure.

Definition at line 47 of file native_support.c.

References Buffer::cap, and Buffer::data.

Referenced by buffer_append().

◆ current_working_directory()

char * current_working_directory ( void )

Returns the current working directory.

Returns
Newly allocated working directory path, or NULL on failure.

Definition at line 310 of file native_support.c.

References pharos_support_getcwd, and pharos_support_strdup.

Referenced by apply_serve_config_defaults_from_conf_native(), executable_dir_from_argv0(), find_repo_root(), load_app_runtime_from_artifact_native(), load_runtime_stack(), resolved_runtime_conf_path_from_config_native(), and runtime_apps_dir_native().

◆ dup_range()

◆ path_canonicalize()

char * path_canonicalize ( const char * path)

Normalizes a path by collapsing redundant separators and dot segments.

Parameters
pathPath to canonicalize.
Returns
Newly allocated canonicalized path, or NULL on failure.

Definition at line 195 of file native_support.c.

References buffer_append(), buffer_free(), buffer_init(), Buffer::data, Buffer::len, PHAROS_SUPPORT_PATH_SEP, and pharos_support_strdup.

Referenced by executable_dir_from_argv0(), find_repo_root(), handle_native_noindex_command(), load_app_runtime_for_single_app(), and match_app_root_in_directory().

◆ path_dirname()

◆ path_exists()

int path_exists ( const char * path)

Tests whether a filesystem path currently exists.

Parameters
pathPath to test.
Returns
Non-zero when the path exists, otherwise 0.

Definition at line 168 of file native_support.c.

References pharos_support_access.

Referenced by app_local_conf_path_native(), app_root_has_finalized_artifact_native(), build_app_from_root_native(), build_dev_docs_directory_native(), build_native_backup_report_local_json(), build_native_restore_report_local_json(), declared_page_relative_path_dup_runtime(), dynamic_conf_lookup_runtime(), emit_website_status_native(), find_repo_root(), generated_surface_fixture_path_dup_runtime(), handle_dynamic_file_signature_command(), handle_native_barcode_command(), handle_page_route(), load_app_local_config_native(), load_app_runtime_from_artifact_native(), load_cli_postgresql_runtime_config(), load_dynamic_postgresql_runtime_config(), load_native_libpq_api_runtime(), load_native_libpq_api_runtime_local(), load_postgresql_runtime_config_runtime_local(), load_runtime_stack(), match_app_root_in_directory(), maybe_seed_app_state_native(), migration_expected_checksum_dup_runtime(), migration_expected_checksum_dup_runtime_local(), native_app_conf_path(), native_append_seed_sources_to_buffer(), native_build_sqlite_migrate_verify_failure_report_json(), native_capture_migrate_verify_sqlite_report_json(), native_db_check_json(), native_dynamic_config_lookup_raw_dup(), native_dynamic_media_serve_asset(), native_dynamic_relational_file_signature_dup(), native_dynamic_relational_sqlite_runtime_ready(), native_dynamic_runtime_handle_request(), native_expected_migration_checksum(), native_legacy_expected_migration_checksum(), native_metadata_artifact_value(), native_migration_fixture_path(), native_migration_schema_version(), native_output_path_check_json(), native_serve_static_file(), native_sqlite_migrate_verify_preflight_ok(), native_write_backup_state_snapshot(), remove_directory_recursive(), remove_media_url_file(), render_declared_page_response_with_headers_runtime(), request_form_field_value_dup_runtime(), and resolve_route_fixture_path().

◆ path_is_directory()

int path_is_directory ( const char * path)

◆ path_is_writable()

int path_is_writable ( const char * path)

Tests whether a filesystem path is writable by the current process.

Parameters
pathPath to test.
Returns
Non-zero when the path is writable, otherwise 0.

Definition at line 191 of file native_support.c.

References pharos_support_access.

Referenced by native_output_path_check_json().

◆ path_join()

char * path_join ( const char * left,
const char * right )

Joins two path segments using the native path separator.

Parameters
leftLeft path segment.
rightRight path segment.
Returns
Newly allocated joined path, or NULL on allocation failure.

Definition at line 115 of file native_support.c.

References PHAROS_SUPPORT_PATH_SEP, and pharos_support_strdup.

Referenced by add_runtime_app_native(), app_artifact_dir_from_build_dir_native(), app_build_dir_local_native(), app_local_conf_path_native(), app_root_has_finalized_artifact_native(), app_runtime_host_profile_native(), app_state_path_local_native(), build_app_from_root_native(), build_dev_docs_directory_native(), build_native_backup_report_local_json(), build_native_restore_report_local_json(), construct_direct_route_fixture_path(), construct_packaged_route_fixture_path(), copy_directory_recursive(), effective_app_artifact_dir_native(), effective_app_state_path_native(), emit_website_status_native(), ensure_media_subtree(), executable_dir_from_argv0(), find_app_root_for_target(), find_repo_root(), handle_native_deploy_package_deb_command(), handle_page_route(), load_app_local_config_native(), load_app_runtime_for_single_app(), load_app_runtime_from_artifact_native(), load_native_libpq_api_runtime(), load_native_libpq_api_runtime_local(), load_runtime_stack(), match_app_root_in_directory(), maybe_seed_app_state_native(), media_disk_path_dup(), migration_fixture_path_dup_runtime_local(), native_app_conf_path(), native_backup_base_dir(), native_build_sqlite_migrate_verify_failure_report_json(), native_capture_migrate_verify_sqlite_report_json(), native_dispatch_response_file_for_request(), native_dynamic_media_resolve_path(), native_dynamic_media_serve_asset(), native_migration_fixture_path(), native_serve_static_file(), native_sqlite_migrate_verify_preflight_ok(), native_website_artifact_dir(), native_website_report_path(), remove_directory_recursive(), resolve_command_path_runtime(), resolve_conf_relative_path_native(), resolve_relative_to(), resolve_route_fixture_path(), resolve_seed_entrypoint_native(), runtime_build_dir_override_native(), runtime_script_path_native(), runtime_state_export_postgresql_path_dup_runtime_local(), runtime_state_export_sqlite_path_dup_runtime_local(), runtime_state_import_postgresql_path_dup_runtime_local(), runtime_state_import_sqlite_path_dup_runtime_local(), store_uploaded_media(), ucal_runtime_state_export_postgresql_path_dup_runtime(), ucal_runtime_state_export_sqlite_path_dup_runtime(), ucal_runtime_state_import_postgresql_path_dup_runtime(), ucal_runtime_state_import_sqlite_path_dup_runtime(), and write_noindex_markers_recursive_native().

◆ read_file_text()

char * read_file_text ( const char * path)

Reads an entire file into a newly allocated text buffer.

Parameters
pathFile path to read.
Returns
Newly allocated text buffer, or NULL on failure.

Definition at line 318 of file native_support.c.

References buffer_append(), buffer_free(), buffer_init(), and Buffer::data.

Referenced by add_runtime_app_native(), app_runtime_host_profile_native(), build_app_from_root_native(), build_dev_docs_directory_native(), conf_lookup_value(), dynamic_relational_runtime_export_json_dup_runtime(), dynamic_relational_runtime_import_state_runtime(), emit_text_file_to_stdout_native(), handle_db_postgresql_exec_file_command(), handle_db_sqlite_exec_file_command(), handle_generated_surface_submitted_command(), handle_native_website_command(), handle_page_route(), handle_template_render_file_command(), load_app_local_config_native(), load_app_runtime_for_single_app(), load_app_runtime_from_artifact_native(), load_runtime_stack(), match_app_root_in_directory(), migration_expected_checksum_dup_runtime(), migration_expected_checksum_dup_runtime_local(), native_append_file_to_buffer(), native_dispatch_response_file_for_request(), native_dynamic_relational_runtime_export_json_dup(), native_dynamic_relational_runtime_import_state(), native_dynamic_runtime_handle_request(), native_json_doc_load_file(), native_legacy_expected_migration_checksum(), native_metadata_artifact_value(), native_migration_fixture_path(), native_migration_schema_version(), postgresql_apply_file_list_runtime(), postgresql_apply_file_list_runtime_local(), render_declared_page_response_with_headers_runtime(), render_file_template_dup_runtime(), request_body_text_dup_runtime(), request_form_field_value_dup_runtime(), resolve_route_fixture_path(), resolve_seed_entrypoint_native(), sqlite_apply_file_list_runtime(), and sqlite_apply_file_list_runtime_local().

◆ resolve_relative_to()

◆ starts_with()

int starts_with ( const char * value,
const char * prefix )

Tests whether one string starts with another string.

Parameters
valueCandidate full string.
prefixPrefix to test.
Returns
Non-zero when value starts with prefix, otherwise 0.

Definition at line 107 of file native_support.c.

Referenced by media_disk_path_dup(), native_dispatch_response_file_for_request(), native_dynamic_media_is_static_path(), native_dynamic_media_resolve_path(), native_dynamic_media_serve_asset(), native_serve_static_file(), remove_media_url_file(), runtime_match_app_native(), and serve_static_root().

◆ streq()

int streq ( const char * a,
const char * b )

Tests whether two strings are exactly equal.

Parameters
aFirst string.
bSecond string.
Returns
Non-zero when the strings are equal, otherwise 0.

Definition at line 111 of file native_support.c.

Referenced by app_artifact_dir_from_build_dir_native(), app_build_dir_local_native(), app_local_conf_value_native(), app_state_path_local_native(), append_generated_admin_surface_form_fields_runtime(), append_generated_admin_surface_rows_runtime(), append_generated_surface_select_options_html_runtime(), apply_base_path_html_dup_runtime(), apply_deb_package_option_native(), apply_serve_config_defaults_from_conf_native(), assign_technician_for_slot_runtime(), assign_technician_for_slot_runtime_local(), build_app_from_root_native(), build_generated_surface_filter_controls_html_runtime(), build_generated_surface_form_fields_html_runtime(), build_generated_surface_sort_options_html_runtime(), build_native_app_doctor_report_local_json(), build_native_app_drift_report_local_json(), build_native_backup_report_local_json(), build_native_restore_report_local_json(), business_calendar_render_page_params_json_dup_runtime(), business_edit_page_params_json_dup_runtime(), business_open_for_slot_runtime(), business_open_for_slot_runtime_local(), capture_migrate_verify_report_json(), copy_directory_recursive(), csrf_request_valid_runtime(), day_of_week_options_html_dup_runtime(), day_of_week_options_html_dup_runtime(), default_signed_in_path_runtime(), diagnostics_render_page_params_json_dup_runtime(), dispatch_native_json_command_entries(), dynamic_config_key_is_path_runtime(), dynamic_relational_runtime_audit_count_dup_runtime(), dynamic_relational_runtime_export_json_dup_runtime(), dynamic_relational_runtime_import_state_runtime(), effective_app_artifact_dir_native(), emit_business_availability_lines_runtime(), emit_business_calendar_render_page_json_runtime(), emit_business_edit_page_json_runtime(), emit_service_book_form_page_json_runtime(), emit_technician_appointments_lines_runtime(), emit_technician_availability_lines_runtime(), emit_user_membership_tenant_ids_json_runtime(), ensure_media_subtree(), event_stream_allowed_by_scope_runtime(), event_stream_matches_filters_runtime(), find_form_field_value_runtime(), find_repo_root(), find_serve_handler_native(), generated_admin_manage_page_params_json_dup_runtime(), generated_admin_surface_descriptor_runtime(), generated_surface_append_audit_event_mut_runtime(), generated_surface_delete_button_label_dup_runtime(), generated_surface_delete_strategy_runtime(), handle_accept_invite_action_runtime(), handle_action_route(), handle_app_or_runtime_request(), handle_bundle_manifest_layer_for_slice_command(), handle_db_postgresql_audit_event_count_command(), handle_db_postgresql_create_database_if_missing_command(), handle_db_postgresql_database_exists_command(), handle_db_postgresql_table_exists_command(), handle_db_sqlite_table_exists_command(), handle_file_generated_surface_match_command(), handle_file_migration_backend_files_json_command(), handle_form_field_json_lines_command(), handle_form_options_html_command(), handle_generated_surface_coerce_candidate_command(), handle_generated_surface_list_columns_json_command(), handle_generated_surface_manage_page_json_command(), handle_generated_surface_manage_table_json_command(), handle_generated_surface_mutate_command(), handle_generated_surface_select_options_html_command(), handle_generated_surface_validation_report_command(), handle_native_backup_restore_ops_command(), handle_native_barcode_command(), handle_native_noindex_command(), handle_native_runtime_app_command(), handle_native_runtime_command(), handle_native_website_command(), handle_object_build_command(), handle_page_route(), handle_password_reset_complete_action_runtime(), handle_password_reset_request_action_runtime(), handle_state_named_command(), handle_state_ucal_import_row_json_lines_command(), handle_template_layout_page_html_command(), handle_template_layout_page_json_command(), json_option_value_runtime(), json_value_equals_text_runtime(), language_options_html_dup_runtime(), load_app_runtime_for_single_app(), load_app_runtime_from_artifact_native(), load_cli_postgresql_runtime_config(), load_dynamic_postgresql_runtime_config(), load_postgresql_runtime_config_runtime_local(), load_runtime_stack(), match_app_root_in_directory(), match_native_ops_command(), membership_role_id_for_invite_runtime_local(), multipart_find_part_runtime(), native_app_runtime_report_id(), native_capture_migrate_verify_sqlite_report_json(), native_db_check_json(), native_dispatch_response_file_for_request(), native_dynamic_config_key_is_path(), native_dynamic_media_is_static_path(), native_dynamic_media_resolve_path(), native_dynamic_media_serve_asset(), native_dynamic_relational_backend_dup(), native_dynamic_relational_postgresql_runtime_prepare(), native_dynamic_relational_postgresql_runtime_ready(), native_dynamic_relational_prepare_request_state(), native_dynamic_relational_runtime_audit_count_dup(), native_dynamic_relational_runtime_export_json_dup(), native_dynamic_relational_runtime_import_state(), native_dynamic_relational_sqlite_runtime_prepare(), native_dynamic_relational_sqlite_runtime_ready(), native_dynamic_relational_sync_back_if_changed(), native_dynamic_runtime_handle_request(), native_environment_valid(), native_migration_checksum_matches(), native_option_value(), native_sqlite_table_exists(), native_sqlite_table_exists(), normalize_base_path_native(), parse_native_app_ops_config(), parse_serve_config_native(), payment_preference_options_html_dup_runtime(), remove_directory_recursive(), render_page_html_dup_runtime(), render_service_visual_html_dup_runtime(), resolve_conf_value_key_native(), resolve_declared_page_params_json_runtime(), resolve_seed_entrypoint_native(), route_request_path_dup_runtime(), route_template_match_into_mut_obj_runtime(), runtime_verb_supported_native(), service_book_form_page_params_json_dup_runtime(), session_cookie_header_dup_runtime(), surface_compare_sort_values_runtime(), surface_context_match_runtime(), surface_filter_item_runtime(), technician_booked_for_slot_runtime(), technician_booked_for_slot_runtime_local(), ucal_declared_fragment_relative_path_runtime(), ucal_declared_page_relative_path_runtime(), user_has_active_tenant_membership_runtime_local(), user_manages_business_runtime(), valid_day_of_week_runtime(), verify_password_hash_runtime(), website_verb_mode_native(), weekday_rank_runtime(), and write_noindex_markers_recursive_native().

◆ trim_in_place()